gpt4 book ai didi

mysql - Xampp无法连接mysql数据库错误请检查数据库名称

转载 作者:行者123 更新时间:2023-11-29 20:26:56 25 4
gpt4 key购买 nike

我附加了 index.php 文件。我在第 37 行收到错误:

"Database connection error: Please check the database name you provided".

我检查了数据库名称是否正确,并尝试了 2 个不同的数据库名称,但出现了相同的错误。有人能告诉我这段代码有什么问题吗?

这是我的 index.php 文件。

if (( isset( $_POST ) && $_POST['submit'] == 'submit' )) {
$SS_license = trim( $_POST['license'] );
$db_host = trim( $_POST['host'] );
$db_name = trim( $_POST['database_name'] );
$db_pass = trim( $_POST['database_password'] );
$db_user = trim( $_POST['database_user'] );
$flag = 0;

if (( 'Database connection error: Please check the host name, user name and password you provided' || $con = mysql_connect( $db_host, $db_user, $db_pass ) )) {
if (mysql_select_db( $db_name, $con )) {
$message .= 'Successfully connected to database<br>';
$flag = 1;
}
else {
$message .= 'Database connection error: Please check the database name you provided<br>';

}
}
else {
$message .= 'Database connection error: Please check the host name, user name and password you provided<br>';
}


if ($flag == 1) {
$fp = fopen( BaseUrl . DS . 'includes' . DS . 'db_inc.php', 'w' );
$string = '<?php';

请告诉我在哪里编辑此代码,以便我可以连接到数据库。

最佳答案

你应该尝试使用下面的代码,这对我来说效果很好。

<小时/>
<?php    $servername = "localhost";$username = "your_username";$password = "your_password";$dbname = "your_DBname"; $conn = mysqli_connect($servername, $username, $password, $dbname);if (!$conn) {die("Connection failed: " . mysqli_connect_error()); } ?>

关于mysql - Xampp无法连接mysql数据库错误请检查数据库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39267038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com