第一次如何创建mysqli数据库? [英] how can I creates a mysqli database for first the first time?
本文介绍了第一次如何创建mysqli数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从 mysqli教程中运行示例.
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";
}
我遇到了错误:
警告:mysqli :: mysqli():(42000/1049):/home/...中的未知数据库'world'
Warning: mysqli::mysqli(): (42000/1049): Unknown database 'world' in /home/...
我应该怎么做才能创建数据库?
What should I do to create the database?
推荐答案
您必须使用此功能:
$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();
这篇关于第一次如何创建mysqli数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文