Location: PHPKode > projects > Tagging manager > version 1.02/includes/dbconn.php
<?php
/*  ============================================================
 *                              dbconn.php 
 *                              -------------------
 *     Date                 : 15 june 2006
 *     E-mail               : hide@address.com
 *
 *     Version              : 1.0 (15/06/2006 - 09:50)
 *
 *     This a free software 
 *     licensed under GPL (General public license)
 *
    ============================================================ */
/**
 * class: iter
 * $sql
 *
 * @version      1.0.0
 * @package Database
 */

/**
 * 	class: DB
 *	$db_server,$db_name,$db_login,$db_pass
 *
 * 	@version      1.0.0
 */    
class DB {
    
    var $_conn_id = 0;
    var $numQueries  = 0;
    var $database;
    
    /**
		* databaseconnection
		*
 		*	@param string $db_server database-server
 		*	@param string $db_name database-name
 		*	@param string $db_login database-login
 		*	@param string $db_pass database-pass
		*/  
    function DB ($db_server,$db_name,$db_login,$db_pass) {
       	$this->_conn_id = @mysql_connect ($db_server,$db_login,$db_pass)
            or trigger_error("Connection Error",1024); 
        @mysql_select_db($db_name, $this->_conn_id) 
            or trigger_error("Database Error",1024);  
        $this->database = $db_name;
    }
    
    /**
		* check querie for error
		*
 		*	@param string $sql sql-string

		*/ 
    function check($sql="") {	
    	$this->numQueries++;
    	if (mysql_error() || !$this->_conn_id) {
    		trigger_error(mysql_error()."\n".$sql,E_USER_ERROR);
        }
        if (debug==3) error_log($sql."\n", 3, '/tmp/sql.log');
    }
}
/**
 * 	class: iter
 *	$sql
 *
 * 	@version      1.0.0
 */
class Iter {
    
    var $_result;
    var $numRows    = 0;
    var $numCols    = 0;
    var $numFetches = 0; // times ->fetch() is called (!= number of succesfull fetches)

    /**
		* Iter: to run selection queries 
		*
 		*	@param string $sql sql-string

		*/     
    function Iter ($sql) {
        global $db;
        global $timer;
        if (debug==3) $timer->addmarker('query_start:');
        $this->_result = mysql_query($sql);
        if (debug==3) $timer->addmarker('query_stop:');
        $db->check($sql);
        $this->numRows = mysql_num_rows($this->_result);
        $this->numCols = mysql_num_fields($this->_result);
    }  
   	/**
		* Fetch: to get the results for the Iter-selection
		*
 		*	@return object results for the query
		*/   
    function fetch() {
        $this->numFetches++;
        if ($this->numCols==1)  {
            list($item) = mysql_fetch_row($this->_result);
            return $item;
        } else 
            return mysql_fetch_object ($this->_result);
    }
}

/**
 * 	class: Query
 *	$sql
 *
 * 	@version      1.0.0
 */
class Query {
    
    var $result;
    var $affectedRows = 0;
    var $insertId = 0;
    
    /**
		* Query: to run a query (delete - update -  insert ...)
		*
		*/ 
    function Query($sql) {
        global $db;
        global $timer;
        if (debug==3) $timer->addmarker('query_start:');
        $this->result = mysql_query($sql);
        if (debug==3) $timer->addmarker('query_stop:');
        $db->check($sql);
        $this->affectedRows = mysql_affected_rows();
        $this->insertId = mysql_insert_id();
    }      
}

$db = new db ($db_server,$db_name,$db_login,$db_pass);
?>
Return current item: Tagging manager