PHP MySQL 创建数据库
自 PHP 4.3 版本起, mysql_create_db() 函数已被废弃。现在推荐使用以下两种替代方法:
- mysqli_query()
- PDO::__query()
PHP MySQLi 创建数据库示例
示例
<?php
host = 'localhost:3306';user = '';
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.