在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 <?php 2 /** 3 * 批量运行sql文件 4 * 正则分隔是重点 preg_split("/;[\r\n]+/", filecontent) 5 */ 6 $config = require '../dataconfig.php'; 7 $dbhost = $config['DB_HOST']; 8 $dbname = $config['DB_USER']; 9 $dbpass = $config['DB_PWD']; 10 $db_database = $config['DB_NAME']; 11 $sqlfile = 'aa.sql'; //运行sql文件地址 12 $db = new mysqli($dbhost, $dbname, $dbpass, $db_database) or die("连接数据库失败!"); 13 $db->query("set names 'utf8'"); 14 $sql_array = preg_split("/;[\r\n]+/", file_get_contents($sqlfile)); 15 foreach ($sql_array as $k => $v) { 16 $result = $db->query($v); 17 if ($result) { 18 echo "Query OK<br/>"; 19 } else { 20 echo $db->error() . '<br>'; 21 } 22 } 23 $db->close();
如果本文章已帮助到您! |
2022-08-30
2022-08-17
2022-11-06
2022-08-17
2022-07-18
请发表评论