Xampp 未连接到 mysql 数据库错误,请检查数据库名称
Xampp not connecting to mysql databse error please check the database name
我附加了 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()); } ?>
我附加了 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()); } ?>