[英]PHP Resource ID error
我想在數據庫中檢索或輸出數據,但我一直收到名為“資源ID”的錯誤。
這是我的代碼:
<?php
$host="localhost";
$username="root";
$password ="123192";
$db_name = "customers";
//Connecting to your Host
mysql_connect("$host","$username","$password") or die("Failed To Connect The server");
//Selecting your Database
mysql_select_db("$db_name") or die("Failed To Select The DB");
$name = $_REQUEST['customerName'];
echo 'WELCOME! <b>'.$name.'</b> We hope that you\'ll Enjoy your stay ';
$sql="SELECT Name FROM `people` WHERE id =2 && Name = 'Kyel'";
$rs=mysql_query($sql);
echo "$rs";
?>
如果我需要改進我的代碼,請告訴我。
mysql_query()
返回一個資源。 to string (通過使用echo
來輸出它來隱式觸發)是資源ID#后跟id。
PHP中的資源只能與其他PHP函數一起使用。 這包括但不限於文件,curl,ftp句柄等。
我可以告訴你......
(a)使用mysql_fetch_array()
(或類似)或
(b)使用PDO 。
后者是更好的建議。
試試這個而不是echo語句:
$array = mysql_fetch_assoc($rs);
var_dump ($array);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.