mysql_query returning false

Asked

Viewed 391 times

1

I’m trying to get information from my database but it’s not returning content, only a fake boolean:

require_once "config.php"; // database
$sql = mysql_query("SELECT * FROM home") or die("MySQL error:".mysql_error()); 
$result = mysql_fetch_array($sql);
var_dump($result);
//echo $result['conteudo'];
while($info = mysql_fetch_array( $sql )) {
  echo $info['conteudo'];
} 

A photo of the result: http://prntscr.com/2xu5to
Any idea what might be going on?

  • I believe the mistake is another

  • But in the other question we come to no conclusion about the error. It is the same code, giving the same problem. So I consider the same question...

  • In fact the other problem was that nothing was happening, and this is the result returning a boolean instead of the text, it would make no sense to edit the other question...

  • There’s something on the table home? The mysql_fetch_array only returns false when the result is empty.

  • Yes, as you can see in this photo: http://prntscr.com/2xu87c

  • This print shows that the table has a defined column, but not that it contains data.

  • By the way, home is a table or is the name of the bank?

  • is a table, and I found a problem, apparently it had not been created the data I had inserted, created and now it appears in the page: array (size=2) 0 => string ' ' (length=1) 'content' => string ' (length=1) 0

  • Problem solved then? I posted my comment as reply.

Show 5 more comments

2 answers

3


If mysql_fetch_array is returning false, is because there is no data in your table. Make sure to enter the data before doing the SELECT.

1

If you do not pass the connection identifier obtained before with the mysql_connect function, PHP will connect with a predefined database in the PHP configuration (or not) when using mysql_query, but this connection may not have been established because the Mysql server address is not well configured.

It is not recommended not to pass connection identifier parameter because of this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.