Location: PHPKode > projects > OSADS Alliance Database > OSADS-2.1/includes/db_class.php
<?php
// +----------------------------------------------------------------------
// | OSADS v2.0
// |
// | PHP Source
// +----------------------------------------------------------------------
// | Copyright (C) 2008 by Frank Tetzel <hide@address.com>
// +----------------------------------------------------------------------
// |
// | OSADS 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.
// |
// | OSADS 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 OSADS. If not, write to the Free Software Foundation, Inc.,
// | 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// |
// +----------------------------------------------------------------------
//

	// Direktzugriff abwehren
	if (!defined('INDEX'))
		die('not allowed');

	class db{
		var $db_link_id;
		var $query_result;
		var $query_count;

		function connect($host, $user, $password, $database){
			$this->db_link_id = mysql_connect($host, $user, $password);
			$this->query_count = 0;
			if($this->db_link_id && mysql_select_db($database, $this->db_link_id)){
				return $this->db_link_id;
			}else{
				return FALSE;
			}
		}

		function disconnect(){
			if($this->db_link_id){
				//$this->free_result();
				return mysql_close($this->db_link_id);
			}else{
				return FALSE;
			}
		}

		function free_result($db_result = 0){
			if($db_result){
				$result = mysql_free_result($db_result);
				unset($db_result);
				return $result;
			}elseif($this->query_result){
				$result = mysql_free_result($this->query_result);
				unset($this->query_result);
				return $result;
			}else{
				return FALSE;
			}
		}

		function query($str, $unsafe=true){
			if ($unsafe)
				trigger_error("Unsafe Query: $str", E_USER_WARNING);
			if($str != ''){
				//echo $str ."<br><br>\n";
				$this->query_result = mysql_query($str, $this->db_link_id)
					or die('mysql_error ('.__FILE__.', '.__LINE__.'):<br>'. $str .'<br>'.mysql_error().'<br><br>'.
							'Please report failure. Continue with back button of your browser.<br><br>'.
							'Fehler bitte melden. Fortsetzen mit der Zur&uuml;ck-Taste des Browsers.<br>');
				$this->query_count++;
				return $this->query_result;
			}else{
				return FALSE;
			}
		}

		function saveQuery() {
			if (func_num_args() < 1){
				trigger_error('saveQuery needs at least one argument', E_USER_ERROR);
			}
			$q = /*stripslashes(*/func_get_arg(0)/*)*/;
			$args = array();
			for ($i=1; $i<func_num_args(); $i++){
				if(is_array(func_get_arg($i))){
					foreach(func_get_arg($i) as $func_arg){
						$args[] = mysql_real_escape_string($func_arg);
					}
				}else{
					$args[] = mysql_real_escape_string(func_get_arg($i));
				}
			}
			//echo $q ."<br>". implode(" ; ", $args) ."<br><br>\n";
			return $this->query(vsprintf($q, $args), false);
		}

		function fetch_array($db_result = 0){
			if($db_result){
				$array = mysql_fetch_array($db_result);
				return $array;
			}elseif($this->query_result){
				$array = mysql_fetch_array($this->query_result);
				return $array;
			}else{
				return FALSE;
			}
		}

		function affected_rows(){
			return mysql_affected_rows($this->db_link_id);
		}
	}
?>
Return current item: OSADS Alliance Database