The PHP API for MySQL

PHP has a suite of built-in functions for interfacing with MySQL database servers. You can get by with a small subset of them, but we'll try to cover the full function list for completeness.

Connecting to a MySQL Database

Table 11.2 shows the functions for connecting to and disconnecting from a MySQL database server and for selecting a database.

Table 11.2. Functions for Connecting to a MySQL Database
FunctionAction
mysql_connect()Opens a connection to a MySQL server
mysql_pconnect()Opens a persistent connection to a MySQL server
mysql_select_db()Selects a MySQL database
mysql_close()Closes a connection to a MySQL server

You can use the following syntax to connect to a MySQL server:

mysql_connect ([server[,username[,password ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.