0
以下の関数をMysql_QueryからMysqliに変更しようとしています。Convertiny Mysql_Query to 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'];
}
?>
を呼び出すために
global $mysqli;
を宣言しますグローバル変数mysqliオブジェクト –ありがとうございます。今すぐ完璧に動作します:) – Trotterwatch