-3

My PHP snippet does not work, var_dump(..) says bool(false) but the db is filled with 1 record. What am I doing wrong?

$sessionResultSet = mysql_query('select * from sessions');
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
George Krause
  • 59
  • 1
  • 3
  • 11
  • One line of code just doesn't cut it. It's like trying to find a black golf ball on the 18th hole at midnight (with no moon anywhere to be found), after drinking rum & coke for all the other 17. *hic!* – Funk Forty Niner Nov 11 '14 at 19:19
  • 1
    Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). You will also want to [Prevent SQL Injection!](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Nov 11 '14 at 19:20
  • 1
    @JayBlanchard Care to join me for a session of rum & coke? We'll need to find someone to drive the golf cart though. – Funk Forty Niner Nov 11 '14 at 19:24
  • 1
    I'm in. My clubs are even cleaned up and ready to go. – Jay Blanchard Nov 11 '14 at 19:25

1 Answers1

3

mysql_queryreturn false if you have an error in your SQL query.

echo mysql_error();

should fix that problem.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • 1
    Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). We need to stop reinforcing bad habits. – Jay Blanchard Nov 11 '14 at 19:20
  • I got a message called "No database selected" but why? after i called mysql_connect i selected my db with "mysql_select_db(...)"? – George Krause Nov 11 '14 at 19:38
  • @GeorgeKrause Is this new code? If so, you're making a mess of things by trying to get it working with this antiquated interface. – tadman Nov 11 '14 at 21:02