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. 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.
How could I alter my query or PHP to return data, rather than a boolean? 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
. 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();
}