通过bluehost中的php连接到MySQL数据库

通过bluehost中的php连接到MySQL数据库,mysql,bluehost,Mysql,Bluehost,嗨,我在bluehost上有一个MYSQL数据库,我正在尝试使用PHP连接到它。使用的PHP文件存储在my domain下的public_html中。下面给出了两个代码 db_config.php <?php /* * All database connection variables */ define('DB_USER', "siveradi_root"); // db user define('DB_PASSWORD', "Tesh123"); // db password (m

嗨,我在bluehost上有一个MYSQL数据库,我正在尝试使用PHP连接到它。使用的PHP文件存储在my domain下的public_html中。下面给出了两个代码

db_config.php

<?php

/*
* All database connection variables
*/

define('DB_USER', "siveradi_root"); // db user
define('DB_PASSWORD', "Tesh123"); // db password (mention your db password here)
define('DB_DATABASE', "siveradi_test"); // database name
define('DB_HOST', "localhost:3306"); // db server
define('DB_PORT',"3306");
?>

db_connect.php

<?php

/**
* A class file to connect to database
*/
class DB_CONNECT {

// constructor
function __construct() {
    // connecting to database
    $this->connect();
}

// destructor
function __destruct() {
    // closing db connection
    $this->close();
}

/**
 * Function to connect with database
 */
function connect() {
    // import database connection variables
    require_once __DIR__ . 'http://mangominds.info/test_mera/db_config.php';

    // Connecting to mysql database
    $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());

    // Selecing database
    $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());

    // returing connection cursor
    return $con;
}

/**
 * Function to close db connection
 */
function close() {
    // closing db connection
    mysql_close();
}

}

?>

但是,当我尝试通过

<?php
$db = new DB_CONNECT(); // creating class object(will open database connection)

?>

显示的错误为“服务器错误网站在检索时遇到错误。它可能因维护而关闭或配置不正确。”


如果您从
define('DB_HOST',“localhost:3306”);//中删除端口,请告知需要执行的操作数据库服务器

并使之:

define('DB_HOST', "localhost"); // db server
另外,尽量不要用端口号注释最后一行,只保留DB_主机定义而不保留端口