Oracle 5.0 Reference Manual page 2252

Table of Contents

Advertisement

"example.com" using the username "user" and the password "password". And a query is run to greet
the user.
Example 20.13. Comparing the three MySQL APIs
<?php
// mysqli
$mysqli = new mysqli("example.com", "user", "password", "database");
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $result->fetch_assoc();
echo htmlentities($row['_message']);
// PDO
$pdo = new PDO('mysql:host=example.com;dbname=database', 'user', 'password');
$statement = $pdo->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);
// mysql
$c = mysql_connect("example.com", "user", "password");
mysql_select_db("database");
$result = mysql_query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = mysql_fetch_assoc($result);
echo htmlentities($row['_message']);
?>
Recommended API
It is recommended to use either the
the old
mysql
extension for new development, as it has been deprecated as of PHP 5.5.0 and will be
removed in the future. A detailed feature comparison matrix is provided below. The overall performance
of all three extensions is considered to be about the same. Although the performance of the extension
contributes only a fraction of the total run time of a PHP web request. Often, the impact is as low as
0.1%.
Feature comparison
PHP version introduced 5.0
Included with PHP 5.x
Development status
Lifecycle
Recommended for new
projects
OOP Interface
Procedural Interface
API supports non-
blocking, asynchronous
queries with mysqlnd
Persistent Connections
API supports Charsets
API supports server-side
Prepared Statements
API supports client-side
Prepared Statements
Overview of the MySQL PHP drivers
mysqli
or
PDO_MySQL
ext/mysqli
Yes
Active
Active
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
2232
extensions. It is not recommended to use
PDO_MySQL
5.1
Yes
Active
Active
Yes
Yes
No
No
Yes
Yes
Yes
Yes
ext/mysql
2.0
Yes
Maintenance only
Deprecated
No
No
Yes
No
Yes
Yes
No
No

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents