Can I query a MySQL database with PDO?

I am very new to PHP and MySQL. I have been told and read that MySQL has been depreciated in PHP. I have also read that the alternatives are to use MySQLi or PDO_MySQL.

I use a shared hosting service to host my website. They only offer MySQL databases.

Am I able to use PDO_MySQL queries on a MySQL database? I didn’t think I could, but I read the following on 3WSchools:

"PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases.

So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries. With MySQLi, you will need to rewrite the entire code - queries included."

The above makes me think I can use PDO_MySQL queries in PHP on the MySQL database?

Yes and PDO is the preferred way to go. Also, use “Prepared Statements” which safeguard your data.

Here is a great tutorial on how to handle it all: PDO the right way

There is a misunderstanding here.

MySQL is a database. mysql_ is a driver (with functions) that old php used to connect to MySQL [the database]. So, yes, mysql_ functions are deprecated and replaced with mysqli_ functions (it means mysql improved). PDO is the industry standard connection driver.

Hopefully this clears up your confusion.

Thank you for your help. I have a better understanding of this now.

Sponsor our Newsletter | Privacy Policy | Terms of Service