2016-06-08 51 views
1

所以,我寫了一些查詢代碼返回true,則返回錯誤:mysqli_multi_query() - 而不是返回數據

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返回數據,而不是布爾值?謝謝

+2

一個電話到**'mysqli_store_result' **,**'mysqli_free_result' **組合,和**'mysqli_next_result' **。 – spencer7593

回答

0

正如在spencer7593的評論中所建議的,我的問題是使用mysqli_store_result,mysqli_free_resultmysqli_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(); 
}