-2

これが私が得ているエラーメッセージです:

警告: mysql_connect() [function.mysql-connect]: 行 29 の /var/www/classes/mysql.class.php でユーザー 'user'@'localhost' (パスワードを使用: YES) のアクセスが拒否されました ERR_DB_CONNECT

私はこのデータベースクラスを使用しています:

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;
} 
4

1 に答える 1

1

ユーザー'user'@'localhostのアクセスが拒否されました

これは、データベース上のアカウントに、クエリを実行するための適切な権限がないことを意味します。データベースを確認してください。XAMPPなどを使用していると思います。データベースを確認するには127.0.0.1、ブラウザに入力してください。データベースにパスワードが添付されている場合、これがアクセスできない理由である可能性があります。


補足として

my_sqlPHPメソッドを使用しないでください。これらは非推奨です。つまり、SQLインジェクションなどのセキュリティ攻撃に対して古く、使用されておらず、脆弱です。PDOオブジェクトまたはmysqliを使用する必要があります。

于 2013-03-10T11:06:52.717 に答える