【PHP MySQL创建数据库】从PHP 4.3开始, 不推荐使用mysql_create_db()函数。现在建议使用两种替代方法之一。
- mysqli_query()
- PDO :: __ query()
<
?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.
推荐阅读
- NVIDIA GeForce 310M,本文教您nvidia geforce 310m驱动安装
- PHP多维数组
- PHP继承任务
- PHP数学操作详解
- PHP邮件用法和实例
- PHP is_null()函数
- PHP魔术常量详解
- PHP include_once包含文件
- PHP Heredoc语法