|
From: Sven <bra...@us...> - 2005-01-09 16:52:24
|
Update of /cvsroot/osbb/osbb/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14127 Added Files: class_db_mysqli.php Log Message: Added MySQLi support --- NEW FILE: class_db_mysqli.php --- <?php /* ******************************************************************************************************************** * filename: class_db_mysqli.php * * description: the database class for the new MySQL inferface (mysqli; PHP5/MySQL4.1 or higher) * * copyright: (c) 2004-2005 osBB Development Group * ******************************************************************************************************************** * $Id: class_db_mysqli.php,v 1.1 2005/01/09 16:52:13 brainstorm2k3 Exp $ ******************************************************************************************************************** *Copyright (C) 2004 osBB Development Group (osbb.sf.net) * *This program is free software; you can redistribute it and/or modify it * *under the terms of the GNU General Public License as published by the * *Free Software Foundation; either version 2 of the License, or (at your option) any later version. * *This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * *without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * *See the GNU General Public License for more details. * *You should have received a copy of the GNU General Public License along with this program; * *if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * ******************************************************************************************************************** * See docs/license.txt for more informations! * ******************************************************************************************************************** */ if(!defined('OSBB')){ die('Go away script kiddie...'); } if(defined('SQL_GETINFO')){ $sqlinfo[$i]['name'] = 'MySQLi (PHP5/MySQL4.1 or higher only!)'; $sqlinfo[$i]['author'] = 'osBB Development Group'; $sqlinfo[$i]['www'] = 'http://osbb.sf.net'; }else{ class sql{ //mysqli (mysql 4.1+) var $server = ''; var $username = ''; var $password = ''; var $database = ''; var $prefix = ''; var $conn = ''; var $lastquery = ''; var $query = ''; function __construct($server,$username,$password,$database,$prefix){ $this->server = $server; $this->username = $username; $this->password = $password; $this->database = $database; $this->prefix = $prefix; $this->queries = array(); $this->connect(); } function connect(){ $this->conn = @mysqli_connect($this->server,$this->username,$this->password,$this->database); if (!$this->conn) $this->error('Cannot connect MySQL database!',0); } function select_db(){ if (!@mysqli_select_db($this->database,$this->conn)) $this->error('Cannot select the database'); } function query($query,$force=0){ @mysqli_commit($this->conn); if($force == 1){ $return = @mysqli_query($this->conn,$query); $this->lastquery = $return; }else{ $check = @mysqli_query($this->conn,$query); if (!$check) $this->error('Error in the MySQL query: '.$query); $this->lastquery = $check; $return = $check; } $this->queries[] = $query; if(!@mysqli_commit($this->conn)) @mysqli_rollback($this->conn); return $return; } function fetch_query($query){ $tofetch = $this->query($query); return mysqli_fetch_array($tofetch); } function fetch_array($row){ return mysqli_fetch_array($row); } function insert_id(){ return mysqli_insert_id($this->conn); } function num_rows($res='none'){ if($res == 'none') $res = $this->lastquery; return mysqli_num_rows($res); } function close(){ mysqli_close($this->conn); } function error($desc,$connected=1){ global $adminmail; $error = ''; $error .= '<b>Warning - MySQLi Error</b><br />'; $error .= 'Description: '.$desc.'<br />'; if($connected == 1){ $error .= 'MySQL Error: '.mysqli_error($this->conn).'<br >'; $error .= 'MySQL Errorno.: '.mysqli_errno($this->conn).'<br >'; }else{ $error .= 'MySQL Error: '.mysqli_connect_error($this->conn).'<br >'; $error .= 'MySQL Errorno.: '.mysqli_connect_errno($this->conn).'<br >'; } $error .= 'Please contact the <a href="mailto:'.$adminmail.'">administrator</a>'; if(DEBUG_MODE == 1) echo $error; else echo '<b>Database Error</b> - Please contact the <a href="mailto:'.$adminmail.'">administrator</a>. If you are the administrator set the constant DEBUG_MODE in lib/constans.php to 1 to get more informations!'; die(); } } } ?> |