所以,我写了一些返回错误的查询代码:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
我知道这是查询的 bool 响应导致的,我已经检查过了,返回的 bool 值等于 true。所以我不明白为什么数据数组没有响应......这是我的代码:
$data = mysqli_multi_query($connection, 'UPDATE teams SET teams.teamViews = teams.TeamViews
+ 1 WHERE (teams.teamID, \''.$userToken.'\') NOT IN (SELECT teams_views.teamId,
teams_views.'.$viewType.' FROM teams_views) AND teams.teamUrl = \''.TEAM_URL.'\';
INSERT INTO teams_views (teamId, '.$viewType.') SELECT t.teamId, \''.$userToken.'\'
FROM teams t WHERE t.teamUrl = \''.TEAM_URL.'\' AND NOT EXISTS (SELECT \''.$userToken.'\'
FROM teams_views WHERE t.teamId = teamId);
SELECT * FROM teams WHERE teams.teamUrl = \''.TEAM_URL.'\';');
$dataRow = mysqli_fetch_array($data, MYSQLI_ASSOC);
SQL 中有三个查询 - 更新、插入和选择。
如何更改我的查询或 PHP 以返回数据而不是 bool 值?谢谢
最佳答案
正如 spencer7593
的评论中所建议的,我的问题是使用 mysqli_store_result
、mysqli_free_result
和 mysqli_next_result< 的组合解决的
。以下是用于执行此操作的函数:
function multi_queries($query, $numQueries) {
$connection = new database_connection();
$data = mysqli_multi_query($connection->connection, $query) or die(mysqli_error($connection->connection));
$data = mysqli_store_result($connection->connection);
if (sizeof($data) > 0) {
$this->success = true;
do {
if ($result = mysqli_store_result($connection->connection)) {
while ($row = mysqli_fetch_row($result)) {
$this->data[sizeof($this->data)] = $row;
}
mysqli_free_result($result);
}
} while (mysqli_next_result($connection->connection));
}
$connection->close_connection();
}
关于php - mysqli_multi_query() - 返回 true 而不是返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37714266/