dongyiluan1718 2012-05-03 18:18
浏览 54
已采纳

自定义mysqli类有php 5.4的错误?

I just had my web-server upgrade to php 5.4 and am getting errors on my sites that use my database class which extends from the built in mysqli. the error is on the last line of my class and despite the error message everything is working fine....

the error message:

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

and the class is:

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....-_-
  • 写回答

1条回答 默认 最新

  • douhuan1950 2012-05-03 18:20
    关注

    custom mysqli class has an error with php 5.4?

    No, not an error, but a strict standard warning. If you consider a warning an error, then yes, your custom mysqli class has an error with php 5.4.

    The strict standard warning reads as follows:

    If you ever intent to extend from the base class. the declaration of the connect function must match with that one of the base class:

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

    In your case it does not:

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

    As you can see, both have different parameters.

    The fix in your case is rather trivial, you just re-use the first parameter, if NULL you provide the class'es own default values:

    /*
     * 
     */
    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();
        }
    }
    

    Take care that port and socket is missing with your default config.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?