[英]mysqli_multi_query() - Returns true instead of returning data
So, I have written some query code returns the error: 所以,我写了一些查询代码返回错误:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
I understand that this is caused to a boolean response from the query, and I have checked it out, and the Boolean returned is equal to true. 我知道这是由查询的布尔响应引起的,我已经检查过它,返回的布尔值等于true。 So I don't see why there is no response with a data array instead... Here's my code:
所以我不明白为什么对数据数组没有响应...这是我的代码:
$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);
There are three queries in the SQL - An update, insert, and selection. SQL中有三个查询 - 更新,插入和选择。
How could I alter my query or PHP to return data, rather than a boolean? 我怎么能改变我的查询或PHP来返回数据,而不是布尔值? Thanks
谢谢
As suggested in a comment by spencer7593
, my question was solved using a combination of mysqli_store_result
, mysqli_free_result
, and mysqli_next_result
. 正如
spencer7593
的评论spencer7593
,我的问题是使用mysqli_store_result
, mysqli_free_result
和mysqli_next_result
的组合解决的。 The following is the function used to do this: 以下是用于执行此操作的函数:
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.