2017-03-18 13 views
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']; 
} 
?> 
+0

を呼び出すためにglobal $mysqli;を宣言しますグローバル変数mysqliオブジェクト –

+1

ありがとうございます。今すぐ完璧に動作します:) – Trotterwatch

答えて

0

は`グローバル$ mysqliのを宣言関数内でグローバル変数mysqliのオブジェクト

<?php 
function get_product_name($pid){ 
global $mysqli; 
$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){ 
global $mysqli; 
$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']; 
} 
?> 
+0

私の答えが正しければそれを合格とマークしてください...こちらをご覧くださいhttps://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work –