自從PHP 4.3起,mysql_create_db()
函式已被棄用。 現在,建議使用以下2
種替代方法之一。
範例
<?php
$host = 'localhost:3306';
$user = 'root'; // MySQL使用者賬號
$pass = '';
$conn = mysqli_connect($host, $user, $pass);
if(! $conn )
{
die('Could not connect: ' . mysqli_connect_error());
}
echo 'Connected successfully<br/>';
$sql = 'CREATE Database mydb';
if(mysqli_query( $conn,$sql)){
echo "Database mydb created successfully.";
}else{
echo "Sorry, database creation failed ".mysqli_error($conn);
}
mysqli_close($conn);
?>
執行上面程式碼,輸出結果如下 -
Connected successfully
Database mydb created successfully.