Mysqli_select_db

  1. Definition and Usage The selectdb / mysqliselectdb function is used to change the default database for the connection.
  2. PHP queries related to “Fatal error: Uncaught ArgumentCountError: mysqliselectdb expects exactly 2 arguments, 1 given in” Warning: mysqlierrno expects exactly 1 paramete; mysqlierror expects exactly 1 argument; mysqlierror expects exactly 1 parameter, 0 given in C: wamp64 www email mail-process.php on line 10.

One of the most important developments in the PHP world was the backward compatibility break for the PHP MySQL extension, which leaves us with two methods to connect to the database: MySQLi.

<?php
mysqli_report
(MYSQLI_REPORT_ERROR MYSQLI_REPORT_STRICT);
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'test');
/* get the name of the current default database */
$result = $mysqli->query('SELECT DATABASE()');
$row = $result->fetch_row();
printf('Default database is %s.n', $row[0]);
/* change default database to 'world' */
$mysqli->select_db('world');
/* get the name of the current default database */
$result = $mysqli->query('SELECT DATABASE()');
$row = $result->fetch_row();
printf('Default database is %s.n', $row[0]);
  • PHP Tutorial
  • Advanced PHP
  • PHP Form Examples
  • PHP login Examples
  • PHP AJAX Examples
  • PHP XML Example
  • PHP Frame Works
  • PHP Design Patterns
  • PHP Function Reference
  • PHP Useful Resources
  • Selected Reading

Definition and Usage

The mysqli_select_db() function accepts a string value representing an existing database and, makes it as a the default database.

Syntax

Parameters

Sr.NoParameter & Description
1

con(Mandatory)

This is an object representing a connection to MySQL Server.

2

name(Mandatory)

This is a string value representing the name of an existing database which you need to make as the default database.

Return Values

The PHP mysqli_select_db() function returns a boolean value which is, true if the operation is successful and, false if not.

PHP Version

Mysql

This function was first introduced in PHP Version 5 and works works in all the later versions.

Example

Following example demonstrates the usage of the mysqli_select_db() function (in procedural style) −

This will produce following result −

Example

Mysqli_select_db Not Working

Mysqli_select_db

In object oriented style the syntax of this function is $con->select_db(); Following is the example of this function in object oriented style $minus;

This will produce following result −

Example

Instead of specifying the database at the time of connection, you can also choose it later using this function as shown below −

Mysqli Select Example

This will produce following result −

Example

Mysqli_select_db() expects exactly 2 parameter

This will produce following result −