0
我在我的json代碼中出現錯誤,如此。警告:mysql_fetch_object():提供的參數不是json中的有效MySQL結果資源
錯誤:
警告:mysql_fetch_object():提供的參數不是在d一個有效的MySQL結果資源:第15行 { 「結果」 \ XAMPP \ XAMPP \ htdocs中\ ROOPA \音樂\ demo.php :空}
php文件:
<?php
@include("db.php");
$query = "SELECT a.a_name as name,b.total_value as value,b.total_votes as votes,a.a_pic as image FROM _album a inner join ratings b on b.a_id=a.id";
$result = mysql_query($query);
// $query1 = "SELECT total_value,total_votes FROM ratings";
//$result1 = mysql_query($query1);
$count = mysql_num_rows($result);
//$count1 = mysql_num_rows($result1);
if($count > 0)
{
while($data = mysql_fetch_object($result))
{
$alb_name =$data->name;
$rate_value = $data->value;
$rate_votes = $data->votes;
$alb_pic =$data->image;
$resmsg[] = array("Album_name"=>$alb_name,"Rating_total_value"=>$rate_value,"Rating_total_votes"=>$rate_votes,"Image_name"=>$alb_pic);
}
$jsonarr = array("result"=>$resmsg);
}
else
{
$jsonarr = array("result"=>"data not found");
}
echo json_encode($jsonarr);
?>
MY db.php中FILE:
<?php
$hostname="localhost";
$username="root";
$password="";
$database="musicalbum";
$conn=mysql_connect($hostname,$username,$password,$database);
$link=mysql_select_db($database,$conn);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
@mysql_close($link);
?>
任何人都可以幫我嗎?
你試過mysql_error()嗎?像這樣... if(!$ result){ die('Invalid query:'。mysql_error()); } – tanaydin
顯而易見的原因是您的數據庫連接失敗或您的查詢失敗。從include語句中刪除錯誤提示符號。 –
得到有關sql錯誤的警告,試試這有助於找出sql錯誤 if(!$ result) die(「mySQL error:」。mysql_error()); –