Location: PHPKode > scripts > Yet Another Pager > yet-another-pager/CYap_db.php
<?PHP
/**
 *
 * Database module abstraction
 *
 * @copyright CYap_db is part of Yap project {@link http://www.andrioli.com/en/yap.html} and it is LGPL
 * @author    Andrioli Darvin <darvin (inside) andrioli (dot) com>
 * @version   $Header: d:\cvs/classistd/yap/CYap_db.php,v 1.12 2008/03/10 12:15:46 darvin Exp $
 */
/*
 * +-------------------------------------------------------------------------+
 * | Yap                                                                     |
 * +-------------------------------------------------------------------------+
 * | Copyright (c) 2003-2008 Andrioli Darvin                                 |
 * | Email         <darvin (inside) andrioli (dot) com>                      |
 * | Web           http://www.andrioli.com/en/yap.html                       |
 * | Download      http://www.phpclasses.org/browse.html/package/1391.html   |
 * |                                                                         |
 * +-------------------------------------------------------------------------+
 * | This library is free software; you can redistribute it and/or modify    |
 * | it under the terms of the GNU Lesser General Public License as          |
 * | published by the Free Software Foundation; either version 2 of the      |
 * | License, or (at your option) any later version.                         |
 * |                                                                         |
 * | This library 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        |
 * | Lesser General Public License for more details.                         |
 * |                                                                         |
 * | You should have received a copy of the GNU Lesser General Public        |
 * | License along with this library; if not, write to the Free Software     |
 * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
 * +-------------------------------------------------------------------------+
 */
/**
 * @package CYap
 */
class CYapDB
{
var $DbConn;
/**
 * Connection to database already open
 * @var boolean
 * @access private
 */
var $Db_Open;
/**
 * Error descritpion from last command
 * @var string
 * @access private
 */
var $txtError;
var $Dbresult;
/**
 * @var array indexed by resource value returned by DbExecSql
 * @access private
 */
var $CurrentRow;
/**
 * @var array sql statement per resource returned by DbExecSql
 * @access private
 */
var $LastQuery;
/**
 *
 */
function CYapDB()
{
$this->LastQuery=array();
$this->CurrentRow=array();
}
/**
 * Open the database connection
 * @param string $server database server
 * @param string $User username
 * @param string $Password User password
 * @access public
 * @return bool true on success, false on failure
 */
function OpenDB($Server,$User="",$Password="")
{
}
function SelectDb($DBname)
{
}
/**
 * Execute the given query
 * @param string $sql sql statement
 * @access public
 * @return bool true on success, false on failure
 */
function DbExecSql($sql)
{
}
/**
 * Perform a select statement using range to limits the
 * rows to return
 * @param string $select select statement
 * @param integer $start no. rows to start
 * @param integer $many how many rows sholud be returned
 * @access public
 * @return bool true on success, false on failure
 */
function QueryLimit($select,$start=0,$many=-1)
{
}
/**
 * Retrieve the number of rows retrieved by the given result
 * @param integer $result
 * @access public
 * @return integer
 */
function DbGetNumRow($result)
{
}
/**
 * Retrieve the number of fields retrieved by the given result
 * @param integer $result
 * @access public
 * @return integer
 */
function DbGetNumFields($result)
{
}
/**
 * Get column information from a result and return as an object
 *
 * @param integer $result
 * @param integer $FieldNo
 * @access public
 * @return object DbMeta
 */
function DbFetchField($result,$FieldNo)
{
}
/**
 * Get the flags associated with the specified field in a result
 * @param resource $result
 * @param integer $FieldNo
 * @access public
 * @return string
 */
function DbFieldFlags($result,$FieldNo)
{
}
/**
 * Free the given result
 * @param integer $result
 * @access public
 * @return bool true on success, false on failure
 */
function DbFreeResult($result)
{
}
/**
 * Escape the string using the db functions, if provided
 * It don't apply the escape string if magic_quotes_gpc is enabled
 *
 * @param string $value sql statement
 * @access public
 * @return string the escaped string
 */
function DbEscape($value)
{
$quote=(bool)ini_get('magic_quotes_gpc');
if(!$quote)
   $ret=addslashes($value);
else
   $ret=$value;
return($ret);
}
/**
 * Return the error descritpion from last command
 * @access public
 * @return string
 */
function DbError()
{
return($this->txtError);
}


/**
 * From an array of values, made the sql for adding the row
 *
 * @param array array of values. The key is the field name
 * @param array type of each fields
 * @param string name of the key field
 * @access public
 */
function DbaddSql($row,$fieldsType,$KeyField)
{
$Count=0;
$fName='';
$fValue='';
foreach($row as $Key => $Value)
   {
   // I Can't update the row key
   if($Key!=$KeyField)
     {
     if($Count)
       {
       $fName.=', ';
       $fValue.=', ';
       }
     $fName.=$Key;
     $apice=$fieldsType[$Key]['apice'];
     $fValue.=$apice.$this->DBEscape($Value).$apice;
     $Count++;
     }
   }
$OutText='('.$fName.') VALUES ('.$fValue.') ';
return($OutText);
}

/**
 *  From an array of values, made the sql for modify the row
 *
 * @param array array of values. The key is the field name
 * @param array type of each fields
 * @access public
 */
function DbmodifySql($row,$fieldsType)
{
$OutText=' set ';
$c=0;
foreach($row as $Key => $Value)
   {
   if($c) $OutText.=', ';
   $apice=$fieldsType[$Key]['apice'];
   $OutText.=$Key.' = '.$apice.$this->DBEscape($Value).$apice.' ';
   $c++;
   }
return($OutText);
}

/**
 * Build the condition string for the $FieldName using the pattern matching
 * syntax
 * @access public
 * @param string
 * @param string
 * @return string
 */
function DbRegexCond($FieldName,$pattern)
{
}
/**
 * Build the condition statement for $FieldName using the 'between' expression
 *
 * @param string $FieldName
 * @param mixed $ValueFrom
 * @param mixed $ValueTo
 * @param string $ValueType
 * @return string
 */
function DbBetweenCond($FieldName,$ValueFrom,$ValueTo,$ValueType)
{
}
}

/*
 ****************
 * CLASS META
 ****************
 */
/**
 * This class mimic the class returnd by mysql_fetch_field
 * @package CYap
 */
class DbMeta
{
var $name;
var $table;
var $type;
var $max_length;
var $numeric;
}


?>
Return current item: Yet Another Pager