Jump to content


Photo

My_mysqli class


  • Please log in to reply
1 reply to this topic

#1 Acs

Acs
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationLisbon, Portugal

Posted 22 March 2006 - 12:42 PM

I tried to make a few additions to the mysqli class, here's the code:


class my_mysqli extends mysqli {
    
    var $mysql_result = array();

    //construtor
    function my_mysqli($server,$username,$password) {    
        parent::mysqli($server,$username,$password) or
            die("Falhou a ligação ao servidor MYSQL - " . $this->error);
    }
    
    function select_db($database) {
        parent::select_db($database) or
            die("Falhou a ligação a base de dados " . $database . $this->error);    
    }
    
    function Query($query) {        
        $this->mysql_result = parent::query($query) or 
            die("Falhou a query - " . $query . $this->error);            
    }        

    function Close() {
        parrent::close();
    }

}


I don't known why but this doesn't work, I always get the firs "or die" -> "Falhou a ligação ao servidor MYSQL"
Which says that the connection to mysql failed. But if I just do a:

$mysqli = new mysqli($server, $username, $password, $database)

It works. Anyone please tell me what I am doing wrong please

Php/Mysql newbie - www.antoniocs.org

#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 22 March 2006 - 12:58 PM

Object oriented programming has changed in PHP5. The constructor is now called "__construct()". I'm not sure how PHP 4.1+ treats mysqli, but you might try:

class my_mysqli extends mysqli {
    
    //construtor
    function my_mysqli($server,$username,$password) {    
        parent::__construct($server,$username,$password) or
            die("Falhou a ligação ao servidor MYSQL - " . $this->error);
    }

}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users