1

Web サーバーを php 5.4 にアップグレードしたところ、組み込みの mysqli から拡張されたデータベース クラスを使用するサイトでエラーが発生しています。エラーはクラスの最後の行にあり、エラーメッセージにもかかわらず、すべて正常に動作しています....

エラーメッセージ:

Strict Standards: Declaration of yamiko_mysqli::connect() should be compatible with mysqli::connect($host = NULL, $user = NULL, $password = NULL, $database = NULL, $port = NULL, $socket = NULL) in /home/markwe6/public_html/_php/yamiko_mysqli.php on line 109

クラスは次のとおりです。

class Yamiko_mysqli extends mysqli
{
    public $host='localhost';
    public $user='markwe6_yamiko';
    public $pass='1chrysanthemum!';
    public $db='markwe6_cp';
    public $result=NULL;#stores most recent result

    /*
     * 
     */
    public function __construct($auto=TRUE)
    {
        if($auto)
        {
            return $this->connect();
        }else
        {
            return TRUE;
        }
    }

    /*
     * 
     */
    public function connect($auto=TRUE, $user=NULL, $pass=NULL, $host=NULL, $db=NULL)
    {
        if($auto)
        {
            parent::__construct($this->host, $this->user, $this->pass, $this->db);
            return $this->check_error();
        }else
        {
            parent::__construct($host, $user, $pass, $db);
            return $this->check_error();
        }
    }

    /*
     * 
     */
    public function query($sql)
    {
        $result=parent::query($sql);
        if($this->check_error())
            return FALSE;
        $this->result=$result;
        return $result;
    }

    /*
     * 
     */
    private function check_error()
    {
        if($this->connect_error!=NULL)
        {
            $GLOBALS['yamiko']->set_error('yamiko_myslqi connection error: '.$this->connect_error);
            return FALSE;
        }elseif ($this->error!=NULL)
        {
            $GLOBALS['yamiko']->set_error('yamiko_myslqi error: '.$this->error);
            return FALSE;
        }
    }
}#this is line 109....-_-
4

1 に答える 1

4

カスタム mysqli クラスに php 5.4 でエラーがありますか?

いいえ、エラーではありませんが、厳密な標準警告です。警告をエラーと見なす場合は、はい、カスタム mysqli クラスに php 5.4 のエラーがあります。

厳格な標準警告は次のとおりです。

基本クラスから拡張する場合。connect 関数の宣言は、基本クラスの宣言と一致する必要があります。

mysqli::connect($host = NULL, $user = NULL, $password = NULL, $database = NULL, $port = NULL, $socket = NULL)

あなたの場合、それはしません:

Yamiko_mysqli::connect($auto=TRUE, $user=NULL, $pass=NULL, $host=NULL, $db=NULL)

ご覧のとおり、どちらも異なるパラメーターを持っています。

NULLあなたの場合の修正はかなり簡単です。クラス独自のデフォルト値を指定する場合は、最初のパラメーターを再利用するだけです。

/*
 * 
 */
public function connect($host = NULL, $user = NULL, $password = NULL, $database = NULL, $port = NULL, $socket = NULL)
{
    if($host === NULL)
    {
        parent::__construct($this->host, $this->user, $this->pass, $this->db);
        return $this->check_error();
    }else
    {
        parent::__construct($host, $user, $password , $database, $port, $socket);
        return $this->check_error();
    }
}

デフォルトの設定では、ポートとソケットが欠落していることに注意してください。

于 2012-05-03T18:20:25.660 に答える