0
我正在嘗試使用Mysql_Query將下面的函數改爲Mysqli。將Mysql_Query轉換爲Mysqli
我似乎在某個地方出了問題,但我沒有得到任何錯誤,它只是沒有通過任何結果。
任何人都可以幫助我做錯了嗎?
原始代碼
<?php
function get_product_name($pid){
$result=mysql_query("select Product_Name from Products where Product_ID=$pid") or die("select Product_Name from Products where Product_ID=$pid"."<br/> <br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['Product_Name'];
}
function get_price($pid){
$result=mysql_query("select ProductPrice from Products where Product_ID=$pid") or die("select ProductPrice from Products where Product_ID=$pid"."<br/> <br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['ProductPrice'];
}
?>
更新的代碼
<?php
function get_product_name($pid){
$result=$mysqli->query("select Product_Name from Products where Product_ID=$pid") or die("select Product_Name from Products where Product_ID=$pid"."<br/><br/>".mysql_error());
$row=$result->fetch_array();
return $row['Product_Name'];
}
function get_price($pid){
$result=$mysqli->query("select ProductPrice from Products where Product_ID=$pid") or die("select ProductPrice from Products where Product_ID=$pid"."<br/><br/>".mysql_error());
$row=$result->fetch_array();
return $row['ProductPrice'];
}
?>
內部函數聲明'全球$ mysqli的;'調用全局變量mysqli對象 –
真棒謝謝你。現在完美的作品:) – Trotterwatch