gpt4 book ai didi

PHP 资源 ID 错误

转载 作者:可可西里 更新时间:2023-11-01 08:07:44 24 4
gpt4 key购买 nike

我想检索或输出数据库中的数据,但我一直收到名为“资源 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()返回一个资源。 到字符串(通过使用 echo 输出它隐式触发)是 Resource ID # 后跟 id。

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

我可以告诉你..

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

(b) 使用 PDO .

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

关于PHP 资源 ID 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7142775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com