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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.