大家好,从文件启动时有一些sql查询的麻烦,但是它的工作是从phpMyAdmin开始的 完整的文件代码:
<?php
ini_set('display_errors', 1); error_reporting(~0);
$mysqli = new mysqli("localhost", "someuser", "somepassword", "data");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else {
printf('OK');
}
$sql = "set @csum := 0;
update data
set kbal = @csum := @csum + kdif order by id";
$result = mysqli_query($mysqli, $sql) or die (mysqli_error($mysqli));
?>
当我开始文件时出现错误:
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 'update data set kbal = @csum := @csum + kdif order by id' at line 2
更新:我发现了错误
我的错误是 - 我使用mysqli_query进行多次查询。当我从
改变陈述时$result = mysqli_query($mysqli, $sql) or die (mysqli_error($mysqli));
到
$result = mysqli_multi_query($mysqli, $sql) or die (mysqli_error($mysqli));
一切都开始有效了!