PHP applications can access MySQL through PDO_MySQL or MySQLi. The original PHP mysql_* extension was deprecated in PHP 5.5 and removed in PHP 7, so code such as mysql_connect() and mysql_query() is historical and must not be used in current applications.
For new applications, start with PDO or MySQLi. Use prepared statements whenever values come from users or other untrusted input.
| Historical topic | Current approach | Tutorial |
|---|---|---|
mysql_connect() / mysql_pconnect() | new PDO(...) or new mysqli(...) | Connections |
mysql_close() | Release PDO reference or call mysqli::close() | Closing connections |
mysql_query() | PDO::query(), PDO::prepare(), mysqli::query() or prepared statements | Executing queries |
mysql_num_rows() | COUNT(*), fetched-row count, or mysqli_result::$num_rows | Counting rows |
mysql_fetch_row() | PDOStatement::fetch(PDO::FETCH_NUM) or mysqli_result::fetch_row() | Fetching rows |
mysql_error() | PDO exceptions / errorInfo() or MySQLi exceptions | Error messages |
mysql_errno() | SQLSTATE / driver code or mysqli::$errno | Error codes |
mysql_list_tables() | SHOW TABLES / INFORMATION_SCHEMA | List tables |
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.