After connecting to the free database management system, you need to perform an operation in MariaDB in order to choose the database in which you want to work. To do this, you have two different options: either you use the command USE in the MySQL command line, or you use the function mysqli_select_db via PHP. We present both methods to you.
The order USE in the command line
The syntax of USE looks like this:
USE nom_de_la_base de données;
sql
You should always use this command in combination with a special database and put it in place of the « database_name » wildcard. If you forgo this setting, you will receive an error message (ERROR 1046).
To be able to illustrate how it works more easily, we are using a simple example. Let’s say we want to call the database « Customers ». The following steps are necessary:
- Connect to your server via the command line:
mysql -u root -p
Enter password: ************
bash
- Use the command
SHOW DATABASESto have an overview of all the databases available on your server:
mysql> SHOW DATABASES;
sql
- To select the desired database, use the command
USE:
You can now work in the database and create a new table with MariaDB CREATE TABLE. If the desired database is not yet listed, create it with the MariaDB command CREATE DATABASE. If a database is no longer needed, delete it with the MariaDB command DROP DATABASE.
The function mysqli_select_db in PHP
SELECT DATABASE for MariaDB is also found in PHP (here: mysqli_select_db). The syntax for the connection is as follows:
$connection = mysqli_connect("server", "username", "password");
php
To select the database, the following command looks like this:
mysqli_select_db($connection, "Clients");
php

