这个问题在这里已经有了答案:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 个回答)
7年前关闭。
我要选择 channel 1
我的 table 看起来像这样
ch_id ch ch_name
1 ch1 channel 1
2 ch2 channel 2
3 ch3 channel 3
4 ch4 channel 4
我尝试使用 url 选择 channel1
exemple.com/channel.php?ch=ch1
当我使用这个
<?php
include('dbconfig.php');
$ch = $_GET['ch'];
$qry="select * from channel_list where ch=".$ch.
$row = mysql_fetch_array(mysql_query($qry));
?>
它告诉我这个错误
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/.../public_html/channel.php on line 5
提前致谢
最佳答案
最好使用 mysqli :) 这会起作用。 Official docs
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
$result = $mysqli->query($query);
/* numeric array */
$row = $result->fetch_array(MYSQLI_NUM);
printf ("%s (%s)\n", $row[0], $row[1]);
/* associative array */
$row = $result->fetch_array(MYSQLI_ASSOC);
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
/* associative and numeric array */
$row = $result->fetch_array(MYSQLI_BOTH);
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);
/* free result set */
$result->free();
/* close connection */
$mysqli->close();
?>
关于php - select * from channel_list where ch=".$ch. doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28201025/