我附上了index.php
文件。我在第37行得到错误:
"数据库连接错误:请检查您提供的数据库名称"。
我检查了数据库名称是否正确,并尝试了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()); } ?>