MySQLi - Select DB - It is used to selects the default database for database queries.
- MySQLi Tutorial
I the link I provided to the manual page for the mysqliselectdb function, note the order of the two arguments (a.k.a. Parameters) that are between the parentheses. The first one is the MySQLi connection or 'link' object, the second one is the name of the database. Mysqliselectdb ใน PHP Programming มีฟังก์ชันที่เกี่ยวข้องกับฐานข้อมูลมากมาย เพื่อให้นักพัฒนาสามารถนำไปใช้ใช้งานได้ง่าย สำหรับความนี้จะอธิบาถึงฟังก์ชัน mysqli.
- MySQLi Useful Resources
- Selected Reading
Once you get connection with MySQLi server, it is required to select a particular database to work with. This is because there may be more than one database available with MySQLi Server.
Syntax
Sr.No. | Parameter & Description |
---|---|
1 | db_name Required - MySQLi Database name to be selected |
2 | connection Optional - if not specified, then last opened connection by mysqli_connect will be used. |
Example
Here is the example showing you how to select a database.
If connected and Selected database successfully,then the sample output should be like this −
- MySQLi Tutorial
- MySQLi Useful Resources
Mysqli_select_db Php
- Selected Reading
The SQL SELECT command is used to fetch data from MySQLi database. You can use this command at mysql> prompt as well as in any script like PHP.
![Mysqli_select_db expects 2 parameters Mysqli_select_db expects 2 parameters](https://otvet.imgsmail.ru/download/25786504_dc77416002d0b7a0ec709351f7121d24.jpg)
Syntax
Here is generic SQL syntax of SELECT command to fetch data from MySQLi table −
- You can use one or more tables separated by comma to include various conditions using a WHERE clause, but WHERE clause is an optional part of SELECT command.
- You can fetch one or more fields in a single SELECT command.
- You can specify star (*) in place of fields. In this case, SELECT will return all the fields.
- You can specify any condition using WHERE clause.
- You can specify an offset using OFFSET from where SELECT will start returning records. By default offset is zero.
- You can limit the number of returns using LIMIT attribute.
Fetching Data from Command Prompt −
This will use SQL SELECT command to fetch data from MySQLi table tutorials_tbl
Example
Following example will return all the records from tutorials_inf table −
Fetching Data Using PHP Script
You can use same SQL SELECT command into PHP function mysqli_query(). This function is used to execute SQL command and later another PHP function mysqli_fetch_assoc() can be used to fetch all the selected data. This function returns row as an associative array, a numeric array, or both. This function returns FALSE if there are no more rows.
Below is a simple example to fetch records from tutorials_inf table.
Example
Try out the following example to display all the records from tutorials_inf table.
The content of the rows are assigned to the variable $row and the values in row are then printed.
Php Select Database
NOTE − Always remember to put curly brackets when you want to insert an array value directly into a string.
Php Mysqli Select Db
The sample output should be like this −