Home  >  Q&A  >  body text

Database connection failed SQLSTATE [HY000][1102]incorrect database name ‘study ‘

<?php
header("Content-type:text/html;charset=utf-8");    //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
// 创建连接
$conn = mysqli_connect($servername, $username, $password);
mysqli_set_charset($conn,'utf8'); //设定字符集
// 检测连接
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}
// 创建数据库
$sql = "CREATE DATABASE study";
if (mysqli_query($conn, $sql)) {
    echo "数据库创建成功";
} else {
    echo "数据库创建失败: " . mysqli_error($conn);
}
mysqli_close($conn);
?>


吥离吥弃吥离吥弃2448 days ago3029

reply all(4)I'll reply

  • 吥离吥弃

    吥离吥弃2018-02-28 10:17:59

    OK, thanks


    reply
    0
  • Don't cry

    Don't cry2018-02-28 10:16:40

    First check whether there is any problem with the PHP code format, then put the SQL statement into mysql and test it to see if there is any problem with the SQL statement, and then look at the mysqli extension problem.

    reply
    0
  • 吥离吥弃

    吥离吥弃2018-02-27 20:22:35


    Yes, there is an error when running


    reply
    0
  • 雕花笼

    雕花笼2018-02-27 20:16:22

    Three codes into one, is your file utf-8 without BOM header?

    reply
    0
  • Cancelreply