PHP implements database operations by installing corresponding extensions. The design of modern applications is inseparable from the application of databases. The current mainstream databases include MsSQL, MySQL, Sybase, Db2, Oracle, PostgreSQL, Access, etc. These Database PHP can install extensions to support it.
Generally speaking, the LAMP architecture refers to: Linux, Apache, Mysql, PHP, so the Mysql database is in PHP The application is very wide. (Recommended learning: PHP programming from entry to proficiency)
A database in PHP may have one or more extensions, including official ones and those provided by third parties. Commonly used extensions for Mysql include the native mysql library, you can also use the enhanced version of mysqli extension, and you can also use PDO for connection and operation.
Different extensions provide basically similar operation methods. The difference is that they may have some new features and the operation performance may be different.
mysql extension method for database connection:
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password');
mysqli extension:
$link = mysqli_connect('mysql_host', 'mysql_user', 'mysql_password');
PDO extension
$dsn = 'mysql:dbname=testdb;host=127.0.0.1'; $user = 'dbuser'; $password = 'dbpass'; $dbh = new PDO($dsn, $user, $password);
The above is the detailed content of Which databases can php connect to?. For more information, please follow other related articles on the PHP Chinese website!