PHP & MySQL® Web Development All-in-One Desk Reference for Dummies®
by Janet Valade, Tricia Ballad, Bill Ballad
5.4. Selecting a Database
If you don't select the 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");
|
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:
mysqli_select_db($cxn,"Customer")
or die ("Couldn't select database.");
If mysqli_select_db can't select the database, the script stops running and the message Couldn't select database. is sent to the browser.
The database stays selected until you select a different database. To select a different database, just use a new mysqli_select_db function statement.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access