How to Select a MySQL Database

If you don’t select the MySQL database in the connect function, you can select the database by using the mysqli_select_db function. You can also use this function to select a different database at any time in your script. The format is

mysqli_select_db($cxn,"databasename")
or die ("message");

If you’re using the mysql functions, rather than the mysqli functions, you must select the database in a separate function, using mysql_select_db.

Fill in the following information:

*cxn: The variable that contains the connection information.

databasename: The name of the database.

*message: The message that’s sent to the browser if the database can’t be selected. The selection might fail because the database can’t be found, which is usually the result of a typo in the database name.

For instance, you can select the database Customer with the following statement: