PHP - Function MySQLi Create DB



Syntax

bool mysqli_create_db ( string $database_name [, resource $link_identifier = NULL ] )

Definition and Usage

It opens a connection to a MySQL Server.

Return Values

It returns true on success or false on failure

Parameters

Sr. No Parameters & Description
1

database_name

It specifies the data base name to be created

Example

Try out the following example

<?php
   $connection = mysql_connect('localhost', 'user_name', 'passwprd');
   
   if (!$connection) {
      die('Could not connect: ' . mysql_error());
   }
   
   $sql = 'CREATE DATABASE my_db';
   
   if (mysql_query($sql, $connection)) {
      echo "Database my_db created successfully\n";
   } else {
      echo 'Error creating database: ' . mysql_error() . "\n";
   }
?>

The result should be as follows −

Database my_db created successfully
php_function_reference.htm
Advertisements