我已将数据库的内容以如下形式转储到 sql 文件中
insert into `a` values
(17,11,5),
(18,12,7),
(19,12,10),
(21,14,45),
(22,15,46),
(24,16,46),
(25,16,49),
(26,17,21),
(27,17,30),
(28,17,45),
(29,17,54),
(30,18,32),
(31,18,35),
(32,19,23),
(33,19,27),
(34,19,54),
(35,20,53),
(36,21,32),
(37,21,35),
(38,21,45),
(39,22,23),
(40,22,30),
(41,22,45),
(57,24,19),
(58,25,46),
(59,26,39),
(60,27,49),
(61,27,56),
(62,28,34);
insert into `b` values (14,'2009-01-06',''),
(15,'2009-02-01',''),
(16,'2009-03-01',''),
(17,'2009-03-25',''),
(18,'2009-04-05',''),
(19,'2009-04-17',''),
(20,'2009-04-18',''),
(21,'2009-04-19',''),
(22,'2009-04-23',''),
(24,'2009-07-05',''),
(25,'2009-08-02',''),
(26,'2009-08-07',''),
(27,'2009-09-06',''),
(28,'2009-09-14','');
etc..
我有 4 个这样的表,没有外键约束。然后我尝试将数据上传到数据库(mysql)中。我读取了文件的内容,将每个表的插入传递到一个数组中,然后对每个元素执行 mysql_query:
$sqlArray = explode(';',$sqlFile);
for($i=0;$i<sizeof($sqlArray);$i++){
mysql_query($sqlArray[$i]) or die ('Error: '.mysql_error());;
}
结果是插入了最后三个表,但没有插入第一个,错误是:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' insert into `a` values (17,11,5), (18,12,7), (19,12,10), (21,14,4' at line 1
我验证了 $sqlArray 具有正确的包含,并且查询是正确的并且可以从 phpmyadmin 运行。
问题似乎与第一个表无关(即即使b
是第一个表也会显示),并且它似乎总是在中间“剪切”查询(或在将近 70 个字符之后)。
任何帮助将不胜感激!