More generally, creating a database within a database management system (DBMS) like MySQL is NOT a direct function of PHP. However, you can do it in PHP if your connection to the DBMS has the appropriate privlidges.
Here is a rather long example of the creation of a database for Micro$oft SQL server in a PHP script. Please note that all of the real "work" is done in the SQL scripts. PHP just passes the scripts to the database server.
$sql="USE master \n";
$sql.="CREATE DATABASE $dbname \n";
$sql.="ON \n";
$sql.="( NAME = '".$dbname."',";
$sql.=" FILENAME = '".$dataloc."\".$dbname_data.".mdf',";
$sql.=" SIZE = 5MB,";
$sql.=" MAXSIZE = 50MB,";
$sql.=" FILEGROWTH = 1MB ) \n";
$sql.="LOG ON \n";
$sql.="( NAME = '".$dbname_log."',";
$sql.=" FILENAME = '".$dataloc."\".$dbname_log.".ldf',";
$sql.=" SIZE = 1MB,";
$sql.=" MAXSIZE = 15MB,";
$sql.=" FILEGROWTH = 1MB ) \n";
echo "<pre>$sql</pre>\n"; //debug line
$h=odbc_connect($datasrc,"sa",$sapass);
if ($h) {
echo "<P>Connected</P>\n";
$r=odbc_exec($h,$sql);
if ($r) {
$i=true;
echo "<P>$appname Database Created</P>\n";
}
else {
$i=false;
echo "<P>$appname Database Creation Failed.</p>\n";
}
} # end if h
if ($h and $i) {
create a user for the database (you don't want to use SA normally
$sql="EXEC sp_addlogin @loginame = '$dbuser', @passwd = '$dbpwd', @defdb = '$dbname'";
$r=odbc_exec($h,$sql);
if ($r) {
$j=true;
echo "<P>$dbuser added to $dbname database</p>\n";
}
else {
$j=false;
echo "<p>Failed to add user $dbuser to $dbname database</p>\n";
}
} # end if h & i
if ($h and $j) {
Grant rights to $dbuser in $dbname
$sql="USE $dbname \n EXEC sp_changedbowner @loginame = '$dbuser'";
$r=odbc_exec($h,$sql);
if ($r) {
echo "<p>$dbuser now owns $dbname.</p>\n";
}
else {
echo "<p>Failed to assigne $dbuser as owner of $dbname.</p>\n";
}
} #end if h & j