Languages - PHP
MySQL Table Connections

How to connect to MySQL tables via PHP. There are 3 different API's This pages discusses the deprecated procedural interface.

Connecting to the database

These scripts will make a database connection.

The constants simplify moving the database from a development system to a production system on another computer - only one file has to change. Typically, the user name and password will be different for security reasons. In addition, the prefix test_ will be removed from the database name.

This code makes the actual connection. At this point, it is possible to query the database and populate a form. I strongly suggest using a separate read/write connection to update the tables.

Closing the database connection

After the page is rendered, this will close the connection.

Call Sequence

Code similar to the following will include the scripts in the correct order to connect to the database, and, after the page has rendered, disconnect from it. While disconnecting is optional, it is also good programming practice - always explicitly close what you open.

Author: Robert Clemenzi
URL: http:// / Languages / PHP / Table_Connections_Procedural.html