Mysql连接数据库用php mysql fetch [复制]

时间:2022-10-20 03:35:17

This question already has an answer here:

这个问题在这里已有答案:

$result = mysql_query("SELECT name FROM internet_shop");
while($row=mysql_fetch_assoc($result))

Its shows errors mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in

它显示错误mysql_fetch_assoc()期望参数1是资源,布尔值在

Databsename:piashhas_piash

One table in database: internet_shop

数据库中的一个表:internet_shop

Runs well in local host Xampp but when on server it shows error can anyone help thanks

在本地主机Xampp中运行良好,但在服务器上显示错误,任何人都可以帮助谢谢

1 个解决方案

#1


1  

Alter the query line to

更改查询行

$result = mysql_query("SELECT name FROM internet_shop") or exit(mysql_error());

Is an error displayed? As ccKep stated, MySQL is deprecated; consider MySQLi.

是否显示错误?正如ccKep所说,MySQL已被弃用;考虑MySQLi。

$connectionId = mysqli_connect($host,$user,$pass) or exit(mysqli_connect_error());
mysqli_select_db($connectionId, "piashhas_piash") or exit(mysqli_error($connectionId));
$result = mysqli_query($connectionId, "SELECT `name` FROM `internet_shop`");
while($row=mysqli_fetch_assoc($result))

#1


1  

Alter the query line to

更改查询行

$result = mysql_query("SELECT name FROM internet_shop") or exit(mysql_error());

Is an error displayed? As ccKep stated, MySQL is deprecated; consider MySQLi.

是否显示错误?正如ccKep所说,MySQL已被弃用;考虑MySQLi。

$connectionId = mysqli_connect($host,$user,$pass) or exit(mysqli_connect_error());
mysqli_select_db($connectionId, "piashhas_piash") or exit(mysqli_error($connectionId));
$result = mysqli_query($connectionId, "SELECT `name` FROM `internet_shop`");
while($row=mysqli_fetch_assoc($result))