AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

SELECT DATABASE in MariaDB: explanation

PARTAGEZ

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:

  1. Connect to your server via the command line:
mysql -u root -p
Enter password: ************

bash

  1. Use the command SHOW DATABASES to have an overview of all the databases available on your server:
mysql> SHOW DATABASES;

sql

  1. 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

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Web Marketing

How to delete a Docker volume?

Keep unused volumes can lead to wasting valuable resources like disk space and computing power. By deleting an unused Docker volume, you improve the efficiency

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact