我正在尋找對此錯誤的解釋/修復。我正在使用以下腳本。這是我第一次使用multi_query:錯誤使用multi_query「調用一個非對象的成員函數multi_query()」
$storyidr=$_POST['storyidr'];
$mysqli = mysqli_connect($dbhost,$dbusername,$dbpasswd,$database_name) or die ("Couldn't connect to server.");
if (mysqli_connect_errno($mysqli))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "INSERT INTO ratings (storyidr, rank, entry_date) VALUES ('$_POST[storyidr]','$_POST[value]',now());";
$sql .= "SELECT AVG(rank) AS avrank from ratings WHERE storyidr = $storyidr";
if($mysqli->multi_query($sql))
{
if ($result = $mysqli->store_result())
{
$data = mysqli_fetch_assoc($result);
$avrank = $data['avrank'];
if(!$result)
{
$arr = array ('status'=>'fail');
echo json_encode($arr);
}
else
{
echo json_encode($avrank);
}
exit;
}
}
旁註 變化:由於它你的代碼是打開[** SQL注入**](http://stackoverflow.com/q/60174/) –