mysql:database_api
This is an old revision of the document!
Table of Contents
MySQL - Database API
Choosing an API
Comparing the three MySQL APIs.
<?php // 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']); // 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']); // 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']); ?>
It is recommended to use either the PDO_MySQL or mysqli extensions. It is not recommended to use the old mysql extension for new development, as it was deprecated in PHP 5.5.0 and was removed in PHP 7.
PDO Tutorial for MySQL Developers
References
mysql/database_api.1476373989.txt.gz · Last modified: 2020/07/15 09:30 (external edit)