2013-02-21 153 views
0

嗨我有一个MYSQL数据库上的BlueHost,我试图连接到它使用PHP。使用的PHP文件存储在我的域下的public_html中。下面给出通过在蓝牙主机连接到MySQL数据库

<?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) 

?> 

连接时显示错误的两个代码

db_config.php说“服务器错误网站在检索http://mangominds.info/test_mera/tt.php时遇到错误。它可能关闭进行维护或配置不正确“

上什么需要

回答

0

也许做,如果你从define('DB_HOST', "localhost:3306"); // db server

删除端口,并请咨询吧:。

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

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