Replies To: No Database Selected error on php page

Re: No Database Selected error on php page

Posted 09 December 2012 - 07:09 PM

Hey.

If you are going to use PDO (which I'd highly recommend!), you have to use PDO to query the database, using either PDO::query() or (preferably) using PDO prepared statements via PDO::prepare(). The mysql_query function, and all the other mysql_* functions, will not work if you use PDO to connect to the database. It's a completely separate system.

You see, it's a completely different approach. It's much cleaner, and relies on a common OOP API rather than cloning the old MySQL C API functions. If you feel that the OOP approach is beyond your current skill level, you might want to consider using MySQLi instead. It offers much the same functionality as the PDO extension, but it also offers procedural functions that mimic the old-school MySQL API. It's far easier for developers used to the mysql_ functions, and those who are perhaps not well versed in OOP yet, to move over to MySQLi than over to PDO. It's worth looking into.