dongyongkui6329 2015-07-08 09:49
浏览 14

快速执行来自文件的多个查询[重复]

This question already has an answer here:

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.
', `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!

</div>
  • 写回答

2条回答 默认 最新

  • dongqiao1158 2015-07-08 09:54
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真