Subsequent to associating with MariaDB, you should choose an information base to work with in light of the fact that numerous data sets may exist. There are two different ways to play out this undertaking: from the order speedy or through a PHP content.
The Command Prompt
In picking an information base at the order brief, essentially use the SQL order 'use' −
[root@host]# mysql -u root -p
Enter password:******
mysql> use PRODUCTS;
Database changed
mysql> SELECT database();
+-------------------------+
| Database |
+-------------------------+
| PRODUCTS |
+-------------------------+
When you select a data set, all ensuing orders will work on the picked information base.
Note − All names (e.g., information base, table, fields) are case delicate. Guarantee orders adjust to the appropriate case.
PHP Select Database Script
PHP gives the mysql_select_db capacity to data set choice. The capacity utilizes two boundaries, one discretionary, and returns an estimation of "valid" on effective choice, or bogus on disappointment.
Syntax
Survey the accompanying select data set content punctuation.
bool mysql_select_db( db_name, connection );
The portrayal of the boundaries is given underneath −
S.No | Parameter & Description |
---|---|
1 |
db_name This required parameter specifies the name of the database to use. |
2 |
connection When not specified, this optional parameter uses the most recent connection used. |
Attempt the accompanying model code for choosing a data set −
<html>
<head>
<title>Select a MariaDB Database</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'guest1';
$dbpass = 'guest1a';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db( 'PRODUCTS' );
mysql_close($conn);
?>
</body>
</html>
On effective determination, you will see the accompanying yield −
mysql> Connected successfully