【问题标题】:Unknown database error when connecting sql database to server (localhost)将 sql 数据库连接到服务器 (localhost) 时出现未知数据库错误
【发布时间】:2021-12-27 15:21:58
【问题描述】:

我应该怎么做才能解决这个错误?

错误:

致命错误:未捕获的 mysqli_sql_exception:未知数据库 'testdb' 在 D:\xampp\htdocs\dashboard\project\connection.php:6 堆栈跟踪:#0 D:\xampp\htdocs\dashboard\project\connection.php (6): mysqli->__construct('localhost', 'root', '#Geoinformatici...', 'testdb') #1 {main} 在 D:\xampp\htdocs\dashboard\project\connection.php 中抛出在第 6 行

括号 IDE 中的代码

<?PHP
    $server = 'localhost';
    $username = 'root';
    $password = '#Geoinformaticionno1';
    $database = 'testdb';
    $connection = new mysqli($server, $username, $password, $database) or die("not connected");
    echo "connected"
?>

让我知道是否需要其他任何东西才能解决此错误。

【问题讨论】:

  • Unknown database 'testdb' 在你的mysql安装中找不到数据库testdb。仔细检查创建了哪些数据库。

标签: php database server xampp localhost


【解决方案1】:

会员!我自己得到了答案... 您只需在这些括号中指定服务器端口即可。

修改后的代码

<?PHP
        $server = 'localhost';
        $username = 'root';
        $password = '#Geoinformaticionno1';
        $database = 'testdb';
        $connection = new mysqli($server, $username, $password, $database, 3307) or die("not 
        connected");
        echo "connected"
        ?>

【讨论】:

  • 3306 是默认端口。如果您更改了它,并且没有反映 php.ini / mysqli.default_port 中的更改,那么您肯定需要为新连接指定它。
猜你喜欢
  • 1970-01-01
  • 2017-12-16
  • 1970-01-01
  • 2014-07-14
  • 1970-01-01
  • 2013-07-09
  • 1970-01-01
  • 2021-08-19
  • 1970-01-01
相关资源
最近更新 更多