PHP MySQL创建数据库

【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.

    推荐阅读