3

我想在数据库中检索或输出数据,但我不断收到名为“资源 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";
?>

如果我需要改进我的代码,请告诉我。

4

2 回答 2

4

mysql_query()返回一个资源。其中的to 字符串(通过使用echoto 输出隐式触发)是Resource ID #后跟 id。

PHP 中的资源只能与其他 PHP 函数一起使用。这包括但不限于文件、curl、ftp 句柄等。

我可以告诉你..

(a) 使用mysql_fetch_array()(或类似的)或

(b) 使用PDO

后者是迄今为止更好的建议。

于 2011-08-22T03:02:30.463 回答
0

试试这个而不是 echo 语句:

$array = mysql_fetch_assoc($rs);
var_dump ($array);
于 2011-08-22T03:06:09.263 回答