所以,我写了一些查询代码返回错误:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
我知道这是由查询的布尔响应引起的,我已经检查过了,返回的布尔值等于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以返回数据,而不是布尔值?感谢
答案 0 :(得分:0)
根据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();
}