我的PHP不是很好,我正在努力處理可能非常簡單的事情。基本上我有以下代碼,如果發現1行,我想將結果設置爲$ aPrds,我該怎麼做?PHP mysqli返回行並設置爲var幫助
$stmt = $db->prepare("select * from products where id=?");
$stmt->bind_param("s", $_GET['id']);
if($stmt->execute())
{
$stmt->store_result();
echo $stmt->num_rows;
if($stmt->num_rows==1)
{
//SET RETURNED ROW TO aPrds
}
else
{
echo "no results or too many found";
}
}
else
{
echo "sql invalid";
}
------------------ UPDATE ------------
我也曾嘗試下面的代碼一直未果(返回(NULL)):
$stmt = $db->prepare("select productid, product_name, description from product where productid=?");
$a=1;
$stmt->bind_param("i", $a);
if($stmt->execute()){
$stmt->store_result();
if($stmt->num_rows==1){
$stmt->bind_result($b, $c, $d);
print_r($b);
print_r($c);
print_r($aPrds);
}else{
echo "no result or more than 1 returned";
}
}else{
echo "invalid sql";
}
請注意,我已經測試過的SQL和它的作品,也是$ DB的mysqli連接肯定是工作。
$ aPrds是VAR的我想回該行。 – Dino