mirror of
https://github.com/dg/dibi.git
synced 2025-10-21 01:36:26 +02:00
* renamed some files libs
* added doc comments to drivers * DibiDriver::prepare() renamed to config() * fixed connection error handling in Postgre driver
This commit is contained in:
@@ -27,6 +27,10 @@
|
||||
*/
|
||||
class DibiMySqlDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
* @var array
|
||||
*/
|
||||
public $formats = array(
|
||||
'TRUE' => "1",
|
||||
'FALSE' => "0",
|
||||
@@ -36,13 +40,15 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
/**
|
||||
* Creates object and (optionally) connects to a database
|
||||
*
|
||||
* @param array connect configuration
|
||||
* @throws DibiException
|
||||
*/
|
||||
public function __construct($config)
|
||||
public function __construct(array $config)
|
||||
{
|
||||
self::prepare($config, 'username', 'user');
|
||||
self::prepare($config, 'password', 'pass');
|
||||
self::config($config, 'username', 'user');
|
||||
self::config($config, 'password', 'pass');
|
||||
|
||||
// default values
|
||||
if ($config['username'] === NULL) $config['username'] = ini_get('mysql.default_user');
|
||||
@@ -58,6 +64,12 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Connects to a database
|
||||
*
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
{
|
||||
if (!extension_loaded('mysql')) {
|
||||
@@ -110,6 +122,13 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
{
|
||||
$connection = $this->getConnection();
|
||||
@@ -124,6 +143,11 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
|
||||
*
|
||||
* @return int number of rows or FALSE on error
|
||||
*/
|
||||
public function affectedRows()
|
||||
{
|
||||
$rows = mysql_affected_rows($this->getConnection());
|
||||
@@ -132,6 +156,11 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
|
||||
*
|
||||
* @return int|FALSE int on success or FALSE on failure
|
||||
*/
|
||||
public function insertId()
|
||||
{
|
||||
$id = mysql_insert_id($this->getConnection());
|
||||
@@ -140,6 +169,10 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @return void
|
||||
*/
|
||||
public function begin()
|
||||
{
|
||||
$this->doQuery('BEGIN');
|
||||
@@ -148,6 +181,10 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @return void
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
$this->doQuery('COMMIT');
|
||||
@@ -156,6 +193,10 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @return void
|
||||
*/
|
||||
public function rollback()
|
||||
{
|
||||
$this->doQuery('ROLLBACK');
|
||||
@@ -164,6 +205,11 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns last error
|
||||
*
|
||||
* @return array with items 'message' and 'code'
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
$connection = $this->getConnection();
|
||||
@@ -175,6 +221,13 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Escapes the string
|
||||
*
|
||||
* @param string unescaped string
|
||||
* @param bool quote string?
|
||||
* @return string escaped and optionally quoted string
|
||||
*/
|
||||
public function escape($value, $appendQuotes = TRUE)
|
||||
{
|
||||
$connection = $this->getConnection();
|
||||
@@ -185,6 +238,12 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Delimites identifier (table's or column's name, etc.)
|
||||
*
|
||||
* @param string identifier
|
||||
* @return string delimited identifier
|
||||
*/
|
||||
public function delimite($value)
|
||||
{
|
||||
return '`' . str_replace('.', '`.`', $value) . '`';
|
||||
@@ -192,6 +251,11 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets a information of the current database.
|
||||
*
|
||||
* @return DibiMetaData
|
||||
*/
|
||||
public function getMetaData()
|
||||
{
|
||||
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
|
||||
@@ -200,7 +264,12 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
/**
|
||||
* @see DibiDriver::applyLimit()
|
||||
* 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
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset = 0)
|
||||
{
|
||||
@@ -225,6 +294,11 @@ class DibiMySqlDriver extends DibiDriver
|
||||
class DibiMySqlResult extends DibiResult
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function rowCount()
|
||||
{
|
||||
return mysql_num_rows($this->resource);
|
||||
@@ -232,6 +306,12 @@ class DibiMySqlResult extends DibiResult
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position
|
||||
* internal usage only
|
||||
*
|
||||
* @return array|FALSE array on success, FALSE if no next record
|
||||
*/
|
||||
protected function doFetch()
|
||||
{
|
||||
return mysql_fetch_assoc($this->resource);
|
||||
@@ -239,6 +319,12 @@ class DibiMySqlResult extends DibiResult
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row
|
||||
*
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
{
|
||||
return mysql_data_seek($this->resource, $row);
|
||||
@@ -246,6 +332,11 @@ class DibiMySqlResult extends DibiResult
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function free()
|
||||
{
|
||||
mysql_free_result($this->resource);
|
||||
|
Reference in New Issue
Block a user