问题描述
一个简单的例子
$connection = MysqLi_connect("domain","user","psw","db");
$response = MysqLi_multi_query($connection,"
SET @a = 'foo';
SET @b = 'bar';
SELECT @a AS A,@b AS B
");
var_dump(MysqLi_field_count(connection));
var_dump(MysqLi_use_result($connection));
var_dump(MysqLi_store_result($connection));
var_dump(MysqLi_more_results($connection));
var_dump(MysqLi_next_result($connection));
退货(美化)
int(0)
bool(false)
bool(false)
bool(true)
bool(true)
怎么了?我只是误解了如何从 MysqLi_multi_query
获取值吗?
为什么它在 0
中返回 MysqLi_field_count
?
如果出现语法错误,如何获取其编号或描述?
提前致谢!
解决方法
不要使用mysqli_multi_query()
。每个查询都应该单独发送到服务器。
这样做:
$response1 = mysqli_query($connection,"SET @a = 'foo'");
$response2 = mysqli_query($connection,"SET @b = 'bar'");
$response3 = mysqli_query($connection,"SELECT @a AS A,@b AS B");
$row = mysqli_fetch_assoc($response3);