1

I am trying to import MySQL data into PHP through the Wordpress PHP Snippet plugin. For whatever reason I keep getting error 'mysql_fetch_array() expects parameter 1 to be resource, boolean'.

My code is as follows:

Connection

[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]

1 Answer 1

2

It is because before the last result the answer of mysql_fetch_array is array but while waits for bolean. Also probably you know it is better to use new MySQLi functions

mysql_select_db('mydatabase');    
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
while (is_array($subjectone = mysql_fetch_array($result)))
{echo $subjectone['dataintable'];}
Sign up to request clarification or add additional context in comments.

1 Comment

I know that in php-documentation there are many examples where while used in same way as @JasonChen used, but in same documentation you'll see that boolean conversion of array is false in same cases. So in this way you'll be able to analise returned result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.