我试图通过Wordpress PHP Snippet插件将MySQL数据导入PHP。无论出于何种原因,我不断收到错误' mysql_fetch_array()期望参数1是资源,布尔'。
我的代码如下:
连接
[insert_php]
$conn = mysql_connect("localhost", "albert", "notrealpassword") or die
(mysql_error());
PHP
mysql_select_db('mydatabase');
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
while ($subjectone = mysql_fetch_array($result))
{echo $subjectone['dataintable'];}
[/insert_php]
答案 0 :(得分:2)
这是因为在最后一个结果之前mysql_fetch_array的答案是数组但是等待bolean。 也许您可能知道使用新的MySQLi函数更好
mysql_select_db('mydatabase');
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
while (is_array($subjectone = mysql_fetch_array($result)))
{echo $subjectone['dataintable'];}