2006-06-04 23:06:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dibi - Database Abstraction Layer according to dgx
|
|
|
|
* --------------------------------------------------
|
|
|
|
*
|
|
|
|
* This source file is subject to the GNU GPL license.
|
|
|
|
*
|
|
|
|
* @author David Grudl aka -dgx- <dave@dgx.cz>
|
2006-11-22 12:55:24 +00:00
|
|
|
* @link http://dibi.texy.info/
|
2007-01-08 00:55:11 +00:00
|
|
|
* @copyright Copyright (c) 2005-2007 David Grudl
|
2006-08-04 14:04:26 +00:00
|
|
|
* @license GNU GENERAL PUBLIC LICENSE v2
|
2006-06-04 23:06:33 +00:00
|
|
|
* @package dibi
|
|
|
|
* @category Database
|
2006-06-07 11:48:20 +00:00
|
|
|
* @version $Revision$ $Date$
|
2006-06-04 23:06:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// security - include dibi.php, not this file
|
2006-06-07 11:48:20 +00:00
|
|
|
if (!defined('DIBI')) die();
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dibi Common Driver
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
abstract class DibiDriver
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Current connection configuration
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected
|
|
|
|
$config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Describes how convert some datatypes to SQL command
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $formats = array(
|
|
|
|
'TRUE' => "1", // boolean true
|
|
|
|
'FALSE' => "0", // boolean false
|
|
|
|
'date' => "'Y-m-d'", // format used by date()
|
|
|
|
'datetime' => "'Y-m-d H:i:s'", // format used by date()
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DibiDriver factory: creates object and connects to a database
|
|
|
|
*
|
2007-02-02 03:51:43 +00:00
|
|
|
* @param array connect configuration
|
2006-11-22 12:55:24 +00:00
|
|
|
* @return DibiDriver
|
2007-02-02 03:51:43 +00:00
|
|
|
* @throw DibiException
|
2006-06-04 23:06:33 +00:00
|
|
|
*/
|
2007-01-29 05:08:52 +00:00
|
|
|
/*abstract disallowed since PHP 5.2*/ static public function connect($config) {}
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-10-26 13:09:56 +00:00
|
|
|
* Protected constructor. Must be initialized using the factory method.
|
|
|
|
* @see DibiDriver::connect()
|
|
|
|
* @param array connect configuration
|
2006-06-04 23:06:33 +00:00
|
|
|
*/
|
|
|
|
protected function __construct($config)
|
|
|
|
{
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the configuration descriptor used by connect() to connect to database.
|
2006-10-26 13:09:56 +00:00
|
|
|
* @see DibiDriver::connect()
|
2006-06-04 23:06:33 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getConfig()
|
|
|
|
{
|
|
|
|
return $this->config;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the SQL query
|
|
|
|
*
|
|
|
|
* @param string SQL statement.
|
2007-01-29 05:08:52 +00:00
|
|
|
* @return object|bool Result set object or TRUE on success, FALSE on failure
|
2006-06-04 23:06:33 +00:00
|
|
|
*/
|
|
|
|
abstract public function query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
|
|
|
|
*
|
|
|
|
* @return int number of rows or FALSE on error
|
|
|
|
*/
|
|
|
|
abstract public function affectedRows();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
|
|
|
|
* @return int|bool int on success or FALSE on failure
|
|
|
|
*/
|
|
|
|
abstract public function insertId();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Begins a transaction (if supported).
|
|
|
|
*/
|
|
|
|
abstract public function begin();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Commits statements in a transaction.
|
|
|
|
*/
|
|
|
|
abstract public function commit();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rollback changes in a transaction.
|
|
|
|
*/
|
|
|
|
abstract public function rollback();
|
|
|
|
|
|
|
|
|
2007-01-29 05:08:52 +00:00
|
|
|
/**
|
|
|
|
* Returns last error
|
|
|
|
* @return array with items 'message' and 'code'
|
|
|
|
*/
|
|
|
|
abstract public function errorInfo();
|
2006-06-04 23:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Escapes the string
|
|
|
|
* @param string unescaped string
|
|
|
|
* @param bool quote string?
|
|
|
|
* @return string escaped and optionally quoted string
|
|
|
|
*/
|
|
|
|
abstract public function escape($value, $appendQuotes = FALSE);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quotes SQL identifier (table's or column's name, etc.)
|
|
|
|
* @param string identifier
|
|
|
|
* @return string quoted identifier
|
|
|
|
*/
|
|
|
|
abstract public function quoteName($value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a information of the current database.
|
|
|
|
*
|
|
|
|
* @return DibiMetaData
|
|
|
|
*/
|
|
|
|
abstract public function getMetaData();
|
|
|
|
|
|
|
|
|
2006-09-23 07:55:11 +00:00
|
|
|
/**
|
|
|
|
* Experimental - injects LIMIT/OFFSET to the SQL query
|
|
|
|
* @param string &$sql The SQL query that will be modified.
|
|
|
|
* @param int $limit
|
|
|
|
* @param int $offset
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
abstract public function applyLimit(&$sql, $limit, $offset = 0);
|
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
|
2006-10-26 13:09:56 +00:00
|
|
|
/**
|
|
|
|
* Undefined property usage prevention
|
|
|
|
*/
|
|
|
|
function __get($nm) { throw new Exception("Undefined property '" . get_class($this) . "::$$nm'"); }
|
|
|
|
function __set($nm, $val) { $this->__get($nm); }
|
|
|
|
private function __unset($nm) { $this->__get($nm); }
|
|
|
|
private function __isset($nm) { $this->__get($nm); }
|
|
|
|
|
|
|
|
|
2006-06-04 23:06:33 +00:00
|
|
|
} // class DibiDriver
|