- MySQLi Tutorial
- MySQLi - Home
- MySQLi - Introduction
- MySQLi - PHP Syntax
- MySQLi - Connection
- MySQLi - Create Database
- MySQLi - Drop Database
- MySQLi - Select Database
- MySQLi - Create Tables
- MySQLi - Drop Tables
- MySQLi - Insert Query
- MySQLi - Select Query
- MySQLi - Where Clause
- MySQLi - Update Query
- MySQLi - Delete Query
- MySQLi - Like Clause
- MySQLi - Sorting Results
- MySQLi - Using Joins
- MySQLi - Handling NULL Values
- Obtaining & Using MySQLi Metadata
- MySQL
- MySQL - Installation
- MySQL - Administration
- MySQL - Data Types
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQLi Useful Resources
- MySQLi - Useful Functions
- MySQLi - Quick Guide
- MySQLi - Useful Resources
- MySQLi - Discussion
MySQLi - Select DB
Syntax
bool mysqli_select_db ( mysqli $link , string $dbname )
Definition and Usage
It is used to selects the default database for database queries.
Example
Try out following example −
<?php $servername = "localhost:3306"; $username = "root"; $password = ""; $dbname = "TUTORIALS"; $tmp = NULL; $conn = new mysqli($servername, $username, $password, $dbname); if (!$conn->real_connect($servername, $username, $password, $dbname)) { die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); } echo 'Success... ' . mysqli_get_host_info($conn) . "\n"; if ($result = $conn->query("SELECT DATABASE()")) { $row = $result->fetch_row(); printf("Default database is %s.\n", $row[0]); $result->close(); } $conn->select_db("test"); if ($result = $conn->query("SELECT DATABASE()")) { $row = $result->fetch_row(); printf("Default database is %s.\n", $row[0]); $result->close(); } $conn->close(); ?>
The sample output of the above code should be like this −
Success... localhost:3306 via TCP/IP Default database is tutorials. Default database is test.
mysqli_useful_functions.htm
Advertisements