【问题标题】:Connecting to a MySQL database via php in bluehost通过 bluehost 中的 php 连接到 MySQL 数据库
【发布时间】:2013-02-21 19:06:13
【问题描述】:

嗨,我在 bluehost 上有一个 MYSQL 数据库,我正在尝试使用 PHP 连接到它。使用的 PHP 文件存储在我的域下的 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)

?>

显示错误提示“服务器错误网站在检索 http://mangominds.info/test_mera/tt.php 时遇到错误。它可能因维护而关闭或配置不正确。”

请就需要做什么提出建议

【问题讨论】:

    标签: mysql bluehost


    【解决方案1】:

    也许如果你从define('DB_HOST', "localhost:3306"); // db server中删除端口

    然后做:

    define('DB_HOST', "localhost"); // db server
    

    也尽量不要用端口号注释最后一行,只留下没有端口的 DB_HOST 定义

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 1970-01-01
      • 2012-12-29
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 2011-12-08
      相关资源
      最近更新 更多