This question already has an answer here:
这个问题在这里已有答案:
- PHP + MySQL transactions examples 9 answers
PHP + MySQL事务示例9个答案
I am trying to insert queries into multiple tables using the following code. I have tried without the TRANSACTION and it will not work, individually they work. Any help would be much appreciated.
Thanks in advance.
我试图使用以下代码将查询插入到多个表中。我已经尝试过没有TRANSACTION,它不会工作,他们单独工作。任何帮助将非常感激。提前致谢。
$query = mysql_query("BEGIN;
INSERT INTO `uc` (`ANO`, `CNO`, `P`) VALUES ('$ano', '$cno', '$p');
INSERT INTO `ct` (`ANO`, `CNO`, `RNO`) VALUES ('$ano','$cno','$rno');
COMMIT;");
$query_run = mysql_query($query);
1 个解决方案
#1
0
$query = "BEGIN";
mysql_query($query) or die (mysql_error());
$query = "INSERT INTO `uc` (`ANO`, `CNO`, `P`) VALUES ('$ano', '$cno', '$p')";
mysql_query($query) or die (mysql_error());
$query = "INSERT INTO `ct` (`ANO`, `CNO`, `RNO`) VALUES ('$ano','$cno','$rno')";
mysql_query($query) or die (mysql_error());
$query = "COMMIT";
mysql_query($query) or die (mysql_error());
#1
0
$query = "BEGIN";
mysql_query($query) or die (mysql_error());
$query = "INSERT INTO `uc` (`ANO`, `CNO`, `P`) VALUES ('$ano', '$cno', '$p')";
mysql_query($query) or die (mysql_error());
$query = "INSERT INTO `ct` (`ANO`, `CNO`, `RNO`) VALUES ('$ano','$cno','$rno')";
mysql_query($query) or die (mysql_error());
$query = "COMMIT";
mysql_query($query) or die (mysql_error());