
April 8th, 2005, 04:46 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 22,309
Time spent in forums: < 1 sec
Reputation Power: 25
|
|
|
RE: mysqli support
I noticed I'm a complete idiot and I posted the code from the unmodified version of ltw_classes. Here is the updated code - it makes use of the db_type variable from the config file, set it to two to use mysqli instead of mysql.
php Code:
Original
- php Code |
|
|
|
///////////////////////////////////////////////////////////////////////////// // class: ltwDb - common DB interface // // Currently, only MySql (type = 1) is supported. // Adding other DB's should be a matter of adding cases to the // "switch" statement for each function. ///////////////////////////////////////////////////////////////////////////// class ltwDb{ var $db_type = ''; var $db_server = ''; var $db_name = ''; var $db_user = ''; var $db_pass = ''; var $db_persistent = ''; var $dbh = ''; // constructor function ltwDb(){ $this->db_type = $ltw_config['db_type']; $this->db_server = $ltw_config['db_server']; $this->db_name = $ltw_config['db_name']; $this->db_user = $ltw_config['db_user']; $this->db_pass = $ltw_config['db_pass']; $this->db_persistent = $ltw_config['db_persistent']; $this->db_connect(); }// end constructor function db_connect(){ switch($this->db_type){ case 1: //mysql if ( $this->db_persistent ){ $this-> dbh = @ mysql_pconnect($this-> db_server, $this-> db_user, $this-> db_pass); }else{ $this-> dbh = @ mysql_connect($this-> db_server, $this-> db_user, $this-> db_pass); } if ( !$this->dbh ){ echo "Error: Connection to MySQL server ". $this-> db_server. " failed.<BR>n"; return; } Error: Connection to MySQL database ".$this->db_server." failed.<BR> "; die ("Error: Fatal db Error.<br>n"); }//end mySQL break; case 2: //mySQLi $this->dbh = @mysqli_connect($this->db_server, $this->db_user, $this->db_pass); if ( !$this->dbh ){ echo "Error: Connection to MySQL server ". $this-> db_server. " failed.<BR>n"; return; } if ( !@mysqli_select_db($this->dbh, $this->db_name) ){ Error: Connection to MySQL database ".$this->db_server." failed.<BR> ------ Code:".@mysqli_errno($this->dbh).",<BR> ------ Message:".@mysqli_error($this->dbh)."<BR> "; die ("Error: Fatal db Error.<br>n"); }//end mySQL break; }//end switch }// end function.db_connect() function db_query($query = ''){ switch( $this->db_type ){ case 1: //mySql if ( !$result ){ Error: A problem was encountered while executing this query.<br> $query<BR><HR>$query<br> "; die ("Error: Fatal db Error.<br>n"); } break; case 2: //mySQLi $result = mysqli_query($this->dbh, $query); if ( !$result ){ Error: A problem was encountered while executing this query.<br> $query<BR><HR>$query<br> "; die ("Error: Fatal db Error.<br>n"); } break; }// end switch return $result; }// end function.db_query() function db_numrows($result){ switch( $this->db_type ){ case 1: //mySQL break; case 2: //mySQLi return mysqli_num_rows($result); break; }// end switch }// end function.db_numrows() function db_fetch_array(&$result){ switch( $this->db_type ){ case 1: //mySQL break; case 2: //mySQLi return mysqli_fetch_array($result); break; }//end switch }//end function.db_fetch_array() }//end class ltwDb
|