How the MySQL Functions Work

Using MySQL from within PHP is a fairly simple business. The general flow of usage is as follows:

  1. Connect to a database server.

  2. Select the database with which you want to work.

  3. Query tables within the selected database.

Note:

Successful queries don’t return the results of the query directly—instead, they return a result handle. Other functions such as mysql_result() and mysql_fetch_row() use the result handle to retrieve the data.

  1. Retrieve the query results.

  2. Disconnect from the database server. (This step is optional; PHP manages MySQL connections automatically, closing them as needed.)

The following script illustrates this flow:

 <pre> <?php // Attempt to connect to the default database server // An ID that refers ...

Get PHP Functions Essential Reference 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.