2016-03-29 4 views
-1

E/InputlineResultへの接続を許可されていません:
警告:にmysql_connect():アクセス ユーザーのために拒否された「ルート」@「デスクトップ2Q0OODR」(パスワードを使用して:NO) Cで:\ XAMPP \ htdocsに\びびり\ mysql.class.php線
3月29日22に
:33:50.633 7032から17538/com.baidar.androidChatter E/InputlineResult:
警告:mysql_connect():アクセス は、 'root' @ 'DESKTOP-2Q0OODR'(パスワード:NOを使用)に対して0123でアクセスできませんC:\ XAMPP \ htdocsに\びびり\ mysql.class.php線
3月29日22に
:33:50.633 7032から17538/com.baidar.androidChatter E/OuterResult:
警告。 mysql_connect():アクセスは 'ルート' ユーザーのための を拒否@ 'デスクトップ2Q0OODR'(パスワード使用:NO)を:\ XAMPP \ htdocsに\おしゃべり\ mysql.class.php
ライン上の警告 Cに:mysql_query()は、パラメータ2が リソースであることを予期します。ブール値は で与えられます。C:\ xampp \ htライン第68回上のドキュメントのコードがFatal Error言う28行で\おしゃべり\ mysql.class.phpライン上
解析エラーは、このMySQLサーバ

<?php 



class MySQL 
{ 
    private $dbLink; 
    private $dbHost; 
    private $dbUsername; 
    private $dbPassword; 
    private $dbName; 
    public $queryCount; 

    function MySQL($dbHost,$dbUsername,$dbPassword,$dbName) 
    { 
     $this->dbHost = $dbHost; 
     $this->dbUsername = $dbUsername; 
     $this->dbPassword = $dbPassword; 
     $this->dbName = $dbName;  
     $this->queryCount = 0;  
    } 
    function __destruct() 
    { 
     $this->close(); 
    } 
    //connect to database 
    private function connect() {  
     $this->dbLink = mysql_connect($this->dbHost, $this->dbUsername, $this->dbPassword);  
     if (!$this->dbLink) {   
      $this->ShowError(); 
      return false; 
     } 
     else if (!mysql_select_db($this->dbName,$this->dbLink)) { 
      $this->ShowError(); 
      return false; 
     } 
     else { 
      mysql_query("set names latin5",$this->dbLink); 
      return true; 
     } 
     unset ($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);  
    } 
    /***************************** 
    * Method to close connection * 
    *****************************/ 
    function close() 
    { 
     @mysql_close($this->dbLink); 
    } 
    /******************************************* 
    * Checks for MySQL Errors 
    * If error exists show it and return false 
    * else return true 
    *******************************************/ 
    function ShowError() 
    { 
     $error = mysql_error(); 
     //echo $error;  
    } 
    /**************************** 
    * Method to run SQL queries 
    ****************************/ 
    function query($sql) 
    { 
     if (!$this->dbLink) 
      $this->connect(); 

     if (! $result = mysql_query($sql,$this->dbLink)) { 
      $this->ShowError();   
      return false; 
     } 
     $this->queryCount++;  
     return $result; 
    } 
    /************************ 
    * Method to fetch values* 
    *************************/ 
    function fetchObject($result) 
    { 
     if (!$Object=mysql_fetch_object($result)) 
     { 
      $this->ShowError(); 
      return false; 
     } 
     else 
     { 
      return $Object; 
     } 
    } 
    /************************* 
    * Method to number of rows 
    **************************/ 
    function numRows($result) 
    { 
     if (false === ($num = mysql_num_rows($result))) { 
      $this->ShowError(); 
      return -1; 
     } 
     return $num;   
    } 
    /******************************* 
    * Method to safely escape strings 
    *********************************/ 
    function escapeString($string) 
    { 
     if (get_magic_quotes_gpc()) 
     { 
      return $string; 
     } 
     else 
     { 
      $string = mysql_escape_string($string); 
      return $string; 
     } 
    } 

    function free($result) 
    { 
     if (mysql_free_result($result)) { 
      $this->ShowError(); 
      return false; 
     } 
     return true; 
    } 

    function lastInsertId() 
    { 
     return mysql_insert_id($this->dbLink); 
    } 

    function getUniqueField($sql) 
    { 
     $row = mysql_fetch_row($this->query($sql)); 

     return $row[0]; 
    } 
    function testconnection() { 
     $this->dbLink = mysql_connect($this->dbHost, $this->dbUsername, $this->dbPassword);  
     if (!$this->dbLink) {   
      $this->ShowError(); 
      return false; 
     } 
     else if (!mysql_select_db($this->dbName,$this->dbLink)) { 
      $this->ShowError(); 
      return false; 
     } 
     else { 
      mysql_query("set names latin5",$this->dbLink); 
      return true; 
     } 
     unset ($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);  
    }  
} 

、それはaccess deniedを言います。

行28-> $ this-> dbLink = mysql_connect($ this-> dbHost、$ this-> dbUsername、$ this-> dbPassword);エラーメッセージはかなりそれをすべて言う(!$結果=するmysql_query($ sqlを、ます$ this-> DBLINK))

+0

これは実際のホスト "DESKTOP-2Q0OODR"ですか?ローカルホストである必要がありますか?これらの接続設定でコンソールクライアントを使用してDBに接続できますか? –

答えて

1

場合
ライン68->。あなたがしようとする資格情報には、データベースにアクセスする権利がありません。大きなヒントは、パスワードメッセージなしでデータベースにアクセスしようとしているというエラーメッセージです。

間違いは、あなたが、これはJavaの&コのように、あなたは非常に多くの言語でのコンストラクタを書く方法であることから、おそらくコンストラクタであることを意図していたMySQL呼ばclassMySQLと呼ばれる機能を書かれているということです。

function __construct($dbHost,$dbUsername,$dbPassword,$dbName) 

また、mysql_は安全でないと判断され、推奨されません。代わりにまたはmysqli_を使用し、SQL injectionsにも注意してください。