0

I have a file with queries. Something like that:

 DROP TABLE IF EXISTS #__assets;
 CREATE TABLE IF NOT EXISTS `#__assets` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key', `parent_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set parent.', `lft` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set lft.', `rgt` int(11) NOT NULL DEFAULT '0' COMMENT 'Nested set rgt.', `level` int(10) unsigned NOT NULL COMMENT 'The cached level in the nested tree.', `name` varchar(50) NOT NULL COMMENT 'The unique name for the asset.\n', `title` varchar(100) NOT NULL COMMENT 'The descriptive title for the asset.', `rules` varchar(5120) NOT NULL COMMENT 'JSON encoded access control.', PRIMARY KEY (`id`), UNIQUE KEY `idx_asset_name` (`name`), KEY `idx_lft_rgt` (`lft`,`rgt`), KEY `idx_parent_id` (`parent_id`) ) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8;
 INSERT INTO #__assets VALUES("1","0","0","165","0","root.1","Root Asset","{\"core.login.site\":{\"6\":1,\"2\":1},\"core.login.admin\":{\"6\":1},\"core.login.offline\":{\"6\":1},\"core.admin\":{\"8\":1},\"core.manage\":{\"7\":1},\"core.create\":{\"6\":1,\"3\":1},\"core.delete\":{\"6\":1},\"core.edit\":{\"6\":1,\"4\":1},\"core.edit.state\":{\"6\":1,\"5\":1},\"core.edit.own\":{\"6\":1,\"3\":1}}");
...

And so...

I can split this file row by row and execute. But this is slow as I have big file. Do you know any faster way to solve this problem?

Thanks!

XTRUST.ORG
  • 3,280
  • 4
  • 34
  • 60

2 Answers2

0

Get file content in a variable as a string

and use mysqli_multi_query()

// condition the queries must be ; seprated

 <?php 

 $queries = get_file_content("filename.sql/or_anyotherfile");

 $result =  mysqli_multi_query($con,$queries);

 ?>

something like this always works for me

Meenesh Jain
  • 2,532
  • 2
  • 19
  • 29
0

you can execute them directly on server by below command, which will be fastest way-

mysql -u<user> -p<pass> db_name < file.sql
Zafar Malik
  • 6,734
  • 2
  • 19
  • 30