0

我附上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';

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

4

1 回答 1

0

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


<?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()); } ?>
于 2016-09-01T09:05:58.717 回答