(PHP 4, PHP 5)
mysql_create_db —Create a MySQL database
This function was deprecated in PHP 4.3.0, and itand the entireoriginal MySQL extension was removed in PHP 7.0.0.Instead, use either the actively developedMySQLi orPDO_MySQL extensions.See also theMySQL: choosing an API guide.Alternatives to this function include:
mysql_create_db() attempts to create a new database on the server associated with the specified link identifier.
database_nameThe name of the database being created.
link_identifierThe MySQL connection. If thelink identifier is not specified, the last link opened bymysql_connect() is assumed. If no such link is found, itwill try to create one as ifmysql_connect() had been calledwith no arguments. If no connection is found or established, anE_WARNING level error is generated.
Example #1mysql_create_db() alternative example
The functionmysql_create_db() is deprecated. It is preferable to usemysql_query() to issue an sqlCREATE DATABASE statement instead.
<?php
$link=mysql_connect('localhost','mysql_user','mysql_password');
if (!$link) {
die('Could not connect: '.mysql_error());
}
$sql='CREATE DATABASE my_db';
if (mysql_query($sql,$link)) {
echo"Database my_db created successfully\n";
} else {
echo'Error creating database: '.mysql_error() ."\n";
}
?>The above example will outputsomething similar to:
Database my_db created successfully
Note:
For backward compatibility, the followingdeprecated alias may be used:mysql_createdb()
Note:
This function will not be available if the MySQL extension was built against a MySQL 4.x client library.
