Selecting the Database

Now that you're connected, the next step is to select which database to use with the mysql_select_db command. It takes two parameters: the database name and, optionally, the database connection. If you don't specify the database connection, the default is the connection from the last mysql_connect:

// Select the database $db_select=mysql_select_db($db_database);

die ("Could not select the database: <br />". mysql_error());

Again, it's good practice to check for an error and display it every time you access the database.

- While it's possible to call mysql_select_db multiple times within the

# 4 same script, it's not considered good practice.

Now that you've got a good database connection, you're ready to execute your SQL query.

Was this article helpful?

0 0

Post a comment