mysqli 的多sql语句执行有关问题
程序员文章站
2024-02-03 14:42:10
...
mysqli 的多sql语句执行问题
为啥会报错:Commands out of sync; you can't run this command now
这句报错,对应的查询语句是
$sql = "select * from login";
$res = $mysqli->query($sql);
非常不解,请答案,没百度到。
------解决方案--------------------
先把multi_query的结果集释放了,再进行查询
//对象创建
$mysqli = new mysqli('localhost', 'root', 'nagiosxi','hrsystem');
//连接是否出错
if($mysqli->connect_error)
{
die('connect database error'.mysqli_connect_error());
}
$sql = "insert into login (user, pass, email, type) values ('dengchao1', md5('dengchao123'), [email protected]', 0);";
$sql .= "insert into login (user1, pass, email, type) values ('dengchao1', md5('dengchao123'), [email protected]', 0)";
$res = $mysqli->multi_query($sql);
if($res && $mysqli->affected_rows > 0)
{
echo "insert ok
rows: ".$mysqli->affected_rows;
}
else
{
//$mysqli->close();
die('insert error
'.$mysqli->error.$mysqli->close());
}
if(!is_bool($res))
{
$res->free();
}
$sql = "select * from login";
$res = $mysqli->query($sql);
echo $mysqli->error."
";
if($res)
{
while($row = $res->fetch_row())
{
foreach($row as $key => $val)
{
echo "--$val";
}
echo "
";
}
}
if(!is_bool($res))
{
$res->free();
}
$mysqli->close();
?>
为啥会报错:Commands out of sync; you can't run this command now
这句报错,对应的查询语句是
$sql = "select * from login";
$res = $mysqli->query($sql);
非常不解,请答案,没百度到。
------解决方案--------------------
先把multi_query的结果集释放了,再进行查询
相关文章
相关视频
上一篇: 和php有关的几种常见安全详解
推荐阅读
-
mysqli 的多sql语句执行有关问题
-
。还得接着。关于PHP中怎么把数组作为sql查询语句的条件,小弟我的代码有有关问题
-
写了一个连接数据库的通用类,SQL语句执行有有关问题
-
mysql版本不同所导致SQL语句执行错误的问题
-
php-mysql 问题笔记一——在命令行中可以执行的sql语句,无法从php页面页面执行!
-
SQL语句这样的写法是否存在有关问题
-
新手刚学PHP,问个SQL插入语句中文乱码的有关问题
-
新手刚学PHP,问个SQL插入语句中文乱码的有关问题
-
SQL语句这样的写法是否存在有关问题
-
php-mysql 问题笔记一——在命令行中可以执行的sql语句,无法从php页面页面执行!