Select problem using php and mysql

Asked

Viewed 28 times

0

I’m new with the development in php and was seeing some examples of select in a table in mysql on the net, but no successful execution.

The code is as follows::

$conexao = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die (mysql_error());
mysql_select_db(DB_NAME, $conexao) or die (mysql_error());  
// CONNECTION ------------------------------------------------------------------


$query = "SELECT * FROM formcontato";
$result = mysql_query($query);    

while($fetch = mysql_fetch_row($result)){
    echo $fetch[0];
}

When the code is executed, it returns the error:

Warning: mysql_fetch_row() expects Parameter 1 to be Resource, Boolean Given in select.php on line 13

What’s wrong with the code above?

  • 1

    mysql_connect was considered discontinued, use MySQLi or PDO to connect to the bank. link with further reading on these extensions of php that manage connections to a database.

  • So Marcelo, obg for the feedback. About Mysqli here gave an error that was related to its activation, as if it had not enabled, but thank you I will read about these 2 forms of connections.

  • Means your query has failed ...

  • on your server go to/phpinfo.php and look for mysqli or pdo they inform you if the extensions are installed on your server, if they are not just installing

No answers

Browser other questions tagged

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