这是我收到的错误消息:
警告:mysql_connect() [function.mysql-connect]:第 29 行 ERR_DB_CONNECT 上 /var/www/classes/mysql.class.php 中用户 'user'@'localhost' 的访问被拒绝(使用密码:YES)
我正在使用这个数据库类:
class mysql
{
public $conn = "";
public $debug = 0;
public $queries = NULL;
public function mysql( $dbUser = "user", $dbPass = "pass", $dbName = "database", $dbHost = "localhost" )
{
global $config;
$this->user = $dbUser;
$this->pass = $dbPass;
$this->name = $dbName;
$this->host = $dbHost;
if ( $this->debug == 1 )
{
$this->queries = array( );
$this->comments = array( );
}
$this->last_result = FALSE;
$this->debug = $config['debug'];
return TRUE;
}
public function connect( )
{
if ( !( $this->conn = mysql_connect( $this->host, $this->user, $this->pass ) ) )
{
exit( "ERR_DB_CONNECT" );
}
$this->select_db( $this->name );
return $this->conn;
}
public function select_db( $db )
{
if ( !mysql_select_db( $db, $this->conn ) )
{
exit( "ERR_MYSQL_SELECT_DB" );
}
$this->query( "set names utf8" );
}
public function query( $query, $comment = "" )
{
if ( !$this->conn )
{
$this->conn = $this->connect( );
}
$start = microtime( );
if ( !( $result = mysql_query( $query, $this->conn ) ) )
{
exit( mysql_error( ) );
}
$end = microtime( );
if ( $this->debug == 1 )
{
list( $usec1, $sec1 ) = explode( " ", $start );
list( $usec2, $sec2 ) = explode( " ", $end );
$diff = round( $sec2 - $sec1 + $usec2 - $usec1, 5 );
$this->queries[] = $query;
$this->comments[] = $comment;
$this->queries['time'][] = $diff;
}
$this->last_result = $result;
return $result;
}