Connecting to MySQL and Selecting the Database
The first step when dealing with MySQL—connecting to the server—requires the appropriately named mysql_connect() function:
$dbc = mysql_connect ($host, $user, $password);
The arguments sent to the function (host, username, and password) are based upon the users and privileges set up within the mysql database (see Appendix A, “Installation,” for more information). Commonly, the host to specify will be localhost but not necessarily (specifying a different host will allow you to connect to MySQL running on a different server).
If the connection was made, the $dbc variable will become a reference point. Most of the PHP functions for working with MySQL can take this as an optional argument but, if ...
Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide 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.