2

我正在运行一个mysqli 教程中的示例。

$mysqli = new mysqli("localhost", "user", "password", "database");
if($mysqli->connect_errno)
{
  echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ) "
  . $mysqli->connect_error;} echo $mysqli->host_info . "\n";
} 

我收到了错误:

警告:mysqli::mysqli(): (42000/1049): /home/中的未知数据库“世界”...

我应该怎么做才能创建数据库?

4

2 回答 2

2

你必须使用这个:

$mysqli=new mysqli("localhost","user","password") or die(".........");

if($mysqli->query("Create database if not exists MyDB")){

   "Failed creating new database: ".$mysqli->connect_errno();
    die();

}

$mysqli->select_db("MyDB");
$mysqli->close();
于 2013-12-14T00:24:40.860 回答
1

尝试这样的事情

$mysqli = new mysqli("localhost", "user", "password");

这样你就连接到数据库了

并将此查询使用mysqli Create Database database1

于 2012-05-28T10:05:45.983 回答