PHP `mysqli_multi_query` 不能 return 值
PHP `mysqli_multi_query` cannot return a value
一个简单的例子
$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));
Returns(美化)
int(0)
bool(false)
bool(false)
bool(true)
bool(true)
怎么了?我只是误解了如何从 mysqli_multi_query
获取值吗?
为什么在 mysqli_field_count
中 return 0
?
如果有语法错误,我怎样才能得到它的编号或描述?
提前致谢!
不要使用 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);
一个简单的例子
$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));
Returns(美化)
int(0)
bool(false)
bool(false)
bool(true)
bool(true)
怎么了?我只是误解了如何从 mysqli_multi_query
获取值吗?
为什么在 mysqli_field_count
中 return 0
?
如果有语法错误,我怎样才能得到它的编号或描述?
提前致谢!
不要使用 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);