【发布时间】: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 时遇到错误。它可能因维护而关闭或配置不正确。”
请就需要做什么提出建议
【问题讨论】: