Location: PHPKode > scripts > New DB Class > new-db-class/sybase_db_class.php
<?php
/* vim: set ts=2 sw=2: */
// +----------------------------------------------------------------------+
// | PHP version 4.0                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002 The PHP Group       |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | hide@address.com so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Ji&#345;í Kocman <hide@address.com>                          |
// +----------------------------------------------------------------------+

/**
* class sybase_db_class
* @package db_class
* @author Ji&#345;í Kocman - hide@address.com
* @version $Id: sybase_db_class.php,v 1.3 2002/11/17 02:57:21 jirka Exp $
*/

class db
{
	var $CONN, $SQL, $DEBUG, $SHOW_ERROR, $LOG_ERROR;
	var $SERVER, $USER, $PASS, $DB, $CHARSET;

	// zapíná-vypíná debug mód - protokolování chyb
	// $ERROR_LOG doporu&#269;uji uvád&#283;t absolutní cestu k souboru
	function debug($DEBUG = 1, $SHOW_ERROR = 1, $LOG_ERROR = 0, $_errorLog = "")
	{
		if ($DEBUG == 1)
		{
			$this->DEBUG = 1;
			if ($_errorLog != "")
			{
				$this->_errorLog = basename($_errorLog);
				$this->_logDir = dirname($_errorLog) . "/";
			}
			else
			{
				$this->_errorLog = "sybase_db_class_error.log";
				$this->_logDir = dirname($GLOBALS['SCRIPT_FILENAME']) . "/logs/";
			}
		}
		else
		{
			$this->DEBUG = 0;
		}
		$this->SHOW_ERROR = $SHOW_ERROR;
		$this->LOG_ERROR = $LOG_ERROR;
	}

	// interní funkce zapisuje chybovou hlášku do error logu
	function _error()
	{
		if ($this->LOG_ERROR == 1)
		{
			$mess = "Došlo k chyb&#283; dne " . date("d.m.Y v H:i:s") . "\n" . @sybase_get_last_message() . "\n\n";
			$f = fopen($this->_logDir . $this->_errorLog, "a");
			@fwrite($f, $mess);
			@fclose($f);
		}
		if ($this->SHOW_ERROR == 1)
		{
			echo "Došlo k chyb&#283; dne " . date("d.m.Y v H:i:s") . "<br>" . @sybase_get_last_message() . "<br><br>";
		}
		return false;
	}

	// funkce navazuje spojení s DB a vrací identifikátor spojení
	function db_Connect($server = "", $user = "", $pass = "", $charset = "")
	{
		if ($server != "")	$this->SERVER = $server;
		if ($user != "")	$this->USER = $user;
		if ($pass != "")	$this->PASS = $pass;
		if ($charset != "")		$this->CHARSET = $charset;
		$this->CONN = @sybase_connect($this->SERVER, $this->USER, $this->PASS, $this->CHARSET);
		if ($this->CONN)
		{
			return $this->CONN;
		}
		else
		{
			if ($this->DEBUG == 1) $this->_error();
			return false;
		}
	}

	// funkce navazuje spojení s DB a vrací identifikátor spojení
	function db_pConnect($server = "", $user = "", $pass = "", $charset = "")
	{
		if ($server != "")	$this->SERVER = $server;
		if ($user != "")	$this->USER = $user;
		if ($pass != "")	$this->PASS = $pass;
		if ($charset != "")		$this->CHARSET = $charset;
		$this->CONN = @sybase_pconnect($this->SERVER, $this->USER, $this->PASS, $this->CHARSET);
		if ($this->CONN)
		{
			return $this->CONN;
		}
		else
		{
			if ($this->DEBUG == 1) $this->_error();
			return false;
		}
	}

	// funkce vybírá databázi, a vrací true pokud byla úsp&#283;šná, jinak vrátí false
	function db_Select_DB($db = "", $conn = "")
	{
		if ($db != "")	$this->DB = $db;
		if ($conn != "")	$this->CONN = $conn;
		$tmp = @sybase_select_db($this->DB,$this->CONN);
		if ($tmp)
		{
			return true;
		}
		else
		{
			if ($this->DEBUG == 1) $this->_error();
			return false;
		}
	}

	// funkce provádí dotaz a vrací identifikátor výsledku, nebo false
	function db_Query($query, $conn = "")
	{
		if ($conn != "")	$this->CONN = $conn;
		$this->SQL = @sybase_query($query, $this->CONN);
		if ($this->SQL)
		{
			return $this->SQL;
		}
		else
		{
			if ($this->DEBUG == 1) $this->_error();
			return false;
		}
	}

	// v sybase neexistuje, takze je to alias pro db_query
	function db_Db_Query($query, $db = "", $conn = "")
	{
		return $this->db_Query($query, $conn);
	}

	// funkce vrací po&#269;et nalezených &#345;ádk&#367; nebo 0
	function db_Num_Rows($sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_num_rows($this->SQL);
		if ($tmp)	return $tmp;
		else		return 0;
	}

	// funkce vrací po&#269;et ovlivn&#283;ních &#345;ádku (UPDATE,INSERT,DELETE) nebo nulu
	function db_Affected_Rows($conn = "")
	{
		if ($conn != "")	$this->CONN = $conn;
		$tmp = @sybase_affected_rows($this->CONN);
		if ($tmp)	return $tmp;
		else		return 0;
	}

	// funkce vrací fetch_row nebo false
	function db_Fetch_Row($sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_fetch_row($this->SQL);
		if ($tmp)	return $tmp;
		else		return false;
	}

	// funkce vrací fetch_row nebo false
	function db_Fetch_Array($sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_fetch_array($this->SQL);
		if ($tmp)	return $tmp;
		else		return false;
	}

	// funkce vrací konkrétní hodnotu výsledku
	function db_Result($radek, $sloupec, $sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_result($this->SQL, $radek, $sloupec);
		if ($tmp)	return $tmp;
		else		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_Insert_Id()
	{
		return false;
	}

	// fukce posune ukazatel na zadaný &#345;ádek
	function db_Data_Seek($radek = 0, $sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_data_seek($this->SQL,$radek);
		if ($tmp)	return $tmp;
		else		return false;
	}

	// funkce uzavírá spojení s databází
	function db_Close($conn = "")
	{
		if ($conn != "")	$this->CONN = $conn;
		$tmp = @sybase_close($this->CONN);
		if ($tmp)	return $tmp;
		else		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_field_name($sloupec = 0, $sql = "")
	{
		return false;
	}

	function db_num_fields($sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_num_fields($this->SQL);
		if ($tmp)	return $tmp;
		else		return 0;
	}

	function db_free_result($sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_free_result($this->SQL);
		if ($tmp)	return $tmp;
		else		return false;
	}

	// vytvoreno pomoci sybase_query, navic je treba prepnout se do db master
	function db_create_db($database,$conn = "")
	{
		if ($conn != "")	$this->CONN = $conn;
		$_tmpdb = $this->DB;
		$this->db_select_db("master");
		$tmp = $this->db_Query("CREATE DATABASE " . $database, $this->CONN);
		$this->db_select_db($_tmpdb);
		if ($tmp)	return true;
		else		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_dbname($radek, $sql = "")
	{
		return false;
	}

	// vytvoreno pomoci sybase_query, navic je treba prepnout se do db master
	function db_drop_db($database, $conn = "")
	{
		if ($conn != "")	$this->CONN = $conn;
		$_tmpdb = $this->DB;
		$this->db_select_db("master");
		$tmp = $this->db_Query("DROP DATABASE " . $database, $this->CONN);
		$this->db_select_db($_tmpdb);
		if ($tmp)	return true;
		else		return false;
	}

	function db_fetch_field($polozka = "", $sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_fetch_field($this->SQL, $polozka);
		if ($tmp)	return $tmp;
		else		return false;
	}

	function db_fetch_object($sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_fetch_object($this->SQL);
		if ($tmp)	return $tmp;
		else		return false;
	}

	function db_field_seek($polozka, $sql = "")
	{
		if ($sql != "")	$this->SQL = $sql;
		$tmp = @sybase_field_seek($this->SQL, $polozka);
		if ($tmp)	return $tmp;
		else		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_field_table($polozka, $sql = "")
	{
		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_field_flags($polozka, $sql = "")
	{
		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_field_len($polozka, $sql = "")
	{
		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_field_type($polozka, $sql = "")
	{
		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_list_fields($table, $db = "", $conn = "")
	{
		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_list_dbs($conn = "")
	{
		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_list_tables($db = "", $conn = "")
	{
		return false;
	}

	// v sybase neni tato funkce implenentovana
	function db_tablename($radek,  $sql = "")
	{
		return false;
	}
}
?>
Return current item: New DB Class