CREATE DATABASE 'some database name' ;
按照期望使用mysql的客户端工作。
来自php / mysqli的相同查询(不同的数据库名称) - 失败了。 它写入INFORMATION_SCHEMA.SCHEMATA 但无法写入mysql.db表?
这实际上是一个更大问题的问题。
发生了什么事。为什么我的mysqli失败了?
代码:
$mysqli = new mysqli("p:127.0.0.1", "root", "showtech123", "mysql");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if(!$mysqli->query( "CREATE DATABASE $database_name;"))
{echo "DATABASE encountered error:" . $mysqli->error . "<br /";}
错误:
db_name: terarydatabase3333, un:teraryuser5999
Warning: mysqli::query(): MySQL server has gone away in /www/admin.showtechllc.com/public_html/adddb.php on line 21
Warning: mysqli::query(): Error reading result set's header in /www/admin.showtechllc.com/public_html/adddb.php on line 21
USER encountered error:MySQL server has gone away
答案 0 :(得分:0)
构造函数中的第四个参数是您要使用的数据库。
您实际上是在尝试在现有数据库中创建新数据库。
试试这个:
$mysqli = new mysqli("p:127.0.0.1", "root", "showtech123");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}else{
echo "connected";
}
if(!$mysqli->query( "CREATE DATABASE $database_name;")){
echo "DATABASE encountered error:" . $mysqli->error . "<br /";
}else{
echo $database_name . "created";
}