gpt4 book ai didi

php - 快速从文件执行多个查询

转载 作者:行者123 更新时间:2023-11-29 22:14:55 25 4
gpt4 key购买 nike

我有一个包含查询的文件。类似这样的事情:

 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 use mysqli_multi_query()

//条件查询必须以;分隔

 <?php 

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

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

?>

这样的事情总是对我有用

关于php - 快速从文件执行多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31289098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com