how can I creates a mysqli database for first the first time?

笑着哭i 提交于 2019-12-31 02:49:30

问题


I was running an example from a mysqli tutorial.

$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";
} 

I was getting the error:

Warning: mysqli::mysqli(): (42000/1049): Unknown database 'world' in /home/...

What should I do to create the database?


回答1:


You have to use this:

$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();



回答2:


try something like this

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

in this way you are connected to database

and put this query using mysqli Create Database database1



来源:https://stackoverflow.com/questions/10781440/how-can-i-creates-a-mysqli-database-for-first-the-first-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!