O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 (but not always), the host to specify will be localhost (naming 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 for all of your subsequent database interactions. Most of the PHP functions for working with MySQL can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required