If you are looking to access MySQL database from your PHP application, there are 3 ways to do it:
- mysql extenstion
- mysqli extension
- PDO extension
You can use any of the above extensions all of which are normally available by default with your installation of PHP.
Mysql extension is the oldest of these extensions. You know that you are using mysql extension when you are accessing your database with functions that look like mysql_*. For example, mysql_connect, mysql_query, e.t.c.
The only trouble with this extension is that it hasn’t quite caught up with the advanced features of MySQL that were made available in more recent years. Therefore this extension is severely limited in terms of mysql features it allows you to use from your application. Prepared statements are one of the features not supported by this extension.
Thus, if you need to use more advanced features like prepared statements from your application, you have to use the other two extensions available in PHP, i.e. mysqli and PDO extensions. These are both modern and more matured extensions that you can use for accessing MySQL from PHP.
mysql and mysqli are very similar in terms of the functions they offer you. For example, for mysql_connect in mysql extenstion, there is mysqli_connect in mysqli. So everytime you use function that looks like mysqli_*, you are using the mysqli extension.
PDO is a different beast. It not only enables you to access most modern features of MySQL, it also allows you to use same functions to access a number of different databases by providing you the consistent APIs . Theoretically, if you want to switch your database from, say, MySQL to PostGreSqL, you could do with just a fewer tweaks. You don’t have to go all over place and rewrite every mysql_* function into pg_* function.
Thus, If you want to use prepared statements, your choices boil down to either mysqli or [URL=“http://php.net/manual/en/pdo.prepared-statements.php”]PDO.