1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00

* some variables renamed

This commit is contained in:
David Grudl
2007-06-25 17:02:12 +00:00
parent a7ddc1547c
commit 5f4dbbbcfd
13 changed files with 199 additions and 199 deletions

View File

@@ -12,7 +12,7 @@
* with this package in the file license.txt.
*
* @author David Grudl
* @copyright Copyright (c) 2004-2007 David Grudl aka -dgx- (http://www.dgx.cz)
* @copyright Copyright (c) 2005-2007 David Grudl aka -dgx- (http://www.dgx.cz)
* @license New BSD License
* @version 0.8d (Revision: $WCREV$, Date: $WCDATE$)
* @category Database
@@ -100,7 +100,7 @@ class dibi
* Current connection
* @var DibiDriver
*/
static private $conn;
static private $connection;
/**
* Last SQL command @see dibi::query()
@@ -175,12 +175,12 @@ class dibi
}
// create connection object and store in list
/** like $conn = $className::connect($config); */
self::$conn = self::$registry[$name] = new $className($config);
/** like $connection = $className::connect($config); */
self::$connection = self::$registry[$name] = new $className($config);
if (dibi::$logAll) dibi::log("OK: connected to DB '$config[driver]'");
return self::$conn;
return self::$connection;
}
@@ -192,7 +192,7 @@ class dibi
*/
static public function isConnected()
{
return (bool) self::$conn;
return (bool) self::$connection;
}
@@ -206,10 +206,10 @@ class dibi
static public function getConnection($name=NULL)
{
if ($name === NULL) {
if (!self::$conn)
if (!self::$connection)
throw new DibiException('Dibi is not connected to database');
return self::$conn;
return self::$connection;
}
if (!isset(self::$registry[$name]))
@@ -229,7 +229,7 @@ class dibi
*/
static public function activate($name)
{
self::$conn = self::getConnection($name);
self::$connection = self::getConnection($name);
}

View File

@@ -57,19 +57,19 @@ class DibiMSSqlDriver extends DibiDriver
$config = $this->config;
if (empty($config['persistent']))
$conn = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE);
$connection = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE);
else
$conn = @mssql_pconnect($config['host'], $config['username'], $config['password']);
$connection = @mssql_pconnect($config['host'], $config['username'], $config['password']);
if (!is_resource($conn))
if (!is_resource($connection))
throw new DibiException("Connecting error (driver mssql)'");
if (!empty($config['database'])) {
if (!@mssql_select_db($config['database'], $conn))
if (!@mssql_select_db($config['database'], $connection))
throw new DibiException("Connecting error (driver mssql)");
}
return $conn;
return $connection;
}
@@ -78,12 +78,12 @@ class DibiMSSqlDriver extends DibiDriver
public function nativeQuery($sql)
{
$this->affectedRows = FALSE;
$conn = $this->getResource();
$res = @mssql_query($sql, $conn);
$connection = $this->getConnection();
$res = @mssql_query($sql, $connection);
if ($res === FALSE) return FALSE;
$this->affectedRows = mssql_rows_affected($conn);
$this->affectedRows = mssql_rows_affected($connection);
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
if (is_resource($res))
@@ -107,19 +107,19 @@ class DibiMSSqlDriver extends DibiDriver
public function begin()
{
return mssql_query('BEGIN TRANSACTION', $this->getResource());
return mssql_query('BEGIN TRANSACTION', $this->getConnection());
}
public function commit()
{
return mssql_query('COMMIT', $this->getResource());
return mssql_query('COMMIT', $this->getConnection());
}
public function rollback()
{
return mssql_query('ROLLBACK', $this->getResource());
return mssql_query('ROLLBACK', $this->getConnection());
}

View File

@@ -73,15 +73,15 @@ class DibiMySqlDriver extends DibiDriver
$php_errormsg = '';
if (empty($config['persistent']))
$conn = @mysql_connect($host, $config['username'], $config['password'], TRUE);
$connection = @mysql_connect($host, $config['username'], $config['password'], TRUE);
else
$conn = @mysql_pconnect($host, $config['username'], $config['password']);
$connection = @mysql_pconnect($host, $config['username'], $config['password']);
if (function_exists('ini_set'))
ini_set('track_errors', $save);
if (!is_resource($conn))
if (!is_resource($connection))
throw new DibiException("Connecting error (driver mysql)'", array(
'message' => mysql_error() ? mysql_error() : $php_errormsg,
'code' => mysql_errno(),
@@ -89,20 +89,20 @@ class DibiMySqlDriver extends DibiDriver
if (!empty($config['charset'])) {
@mysql_query("SET NAMES '" . $config['charset'] . "'", $conn);
@mysql_query("SET NAMES '" . $config['charset'] . "'", $connection);
// don't handle this error...
}
if (!empty($config['database'])) {
if (!@mysql_select_db($config['database'], $conn))
if (!@mysql_select_db($config['database'], $connection))
throw new DibiException("Connecting error (driver mysql)", array(
'message' => mysql_error($conn),
'code' => mysql_errno($conn),
'message' => mysql_error($connection),
'code' => mysql_errno($connection),
));
}
return $conn;
return $connection;
}
@@ -111,15 +111,15 @@ class DibiMySqlDriver extends DibiDriver
public function nativeQuery($sql)
{
$this->insertId = $this->affectedRows = FALSE;
$conn = $this->getResource();
$res = @mysql_query($sql, $conn);
$connection = $this->getConnection();
$res = @mysql_query($sql, $connection);
if ($res === FALSE) return FALSE;
$this->affectedRows = mysql_affected_rows($conn);
$this->affectedRows = mysql_affected_rows($connection);
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
$this->insertId = mysql_insert_id($conn);
$this->insertId = mysql_insert_id($connection);
if ($this->insertId < 1) $this->insertId = FALSE;
if (is_resource($res))
@@ -143,38 +143,38 @@ class DibiMySqlDriver extends DibiDriver
public function begin()
{
return mysql_query('BEGIN', $this->getResource());
return mysql_query('BEGIN', $this->getConnection());
}
public function commit()
{
return mysql_query('COMMIT', $this->getResource());
return mysql_query('COMMIT', $this->getConnection());
}
public function rollback()
{
return mysql_query('ROLLBACK', $this->getResource());
return mysql_query('ROLLBACK', $this->getConnection());
}
public function errorInfo()
{
$conn = $this->getResource();
$connection = $this->getConnection();
return array(
'message' => mysql_error($conn),
'code' => mysql_errno($conn),
'message' => mysql_error($connection),
'code' => mysql_errno($connection),
);
}
public function escape($value, $appendQuotes=TRUE)
{
$conn = $this->getResource();
$connection = $this->getConnection();
return $appendQuotes
? "'" . mysql_real_escape_string($value, $conn) . "'"
: mysql_real_escape_string($value, $conn);
? "'" . mysql_real_escape_string($value, $connection) . "'"
: mysql_real_escape_string($value, $connection);
}

View File

@@ -64,18 +64,18 @@ class DibiMySqliDriver extends DibiDriver
{
$config = $this->config;
$conn = @mysqli_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
$connection = @mysqli_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
if (!$conn)
if (!$connection)
throw new DibiException("Connecting error (driver mysqli)", array(
'message' => mysqli_connect_error(),
'code' => mysqli_connect_errno(),
));
if (!empty($config['charset']))
mysqli_query($conn, "SET NAMES '" . $config['charset'] . "'");
mysqli_query($connection, "SET NAMES '" . $config['charset'] . "'");
return $conn;
return $connection;
}
@@ -83,15 +83,15 @@ class DibiMySqliDriver extends DibiDriver
public function nativeQuery($sql)
{
$this->insertId = $this->affectedRows = FALSE;
$conn = $this->getResource();
$res = @mysqli_query($conn, $sql);
$connection = $this->getConnection();
$res = @mysqli_query($connection, $sql);
if ($res === FALSE) return FALSE;
$this->affectedRows = mysqli_affected_rows($conn);
$this->affectedRows = mysqli_affected_rows($connection);
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
$this->insertId = mysqli_insert_id($conn);
$this->insertId = mysqli_insert_id($connection);
if ($this->insertId < 1) $this->insertId = FALSE;
if (is_object($res))
@@ -115,34 +115,34 @@ class DibiMySqliDriver extends DibiDriver
public function begin()
{
return mysqli_autocommit($this->getResource(), FALSE);
return mysqli_autocommit($this->getConnection(), FALSE);
}
public function commit()
{
$conn = $this->getResource();
$ok = mysqli_commit($conn);
mysqli_autocommit($conn, TRUE);
$connection = $this->getConnection();
$ok = mysqli_commit($connection);
mysqli_autocommit($connection, TRUE);
return $ok;
}
public function rollback()
{
$conn = $this->getResource();
$ok = mysqli_rollback($conn);
mysqli_autocommit($conn, TRUE);
$connection = $this->getConnection();
$ok = mysqli_rollback($connection);
mysqli_autocommit($connection, TRUE);
return $ok;
}
public function errorInfo()
{
$conn = $this->getResource();
$connection = $this->getConnection();
return array(
'message' => mysqli_error($conn),
'code' => mysqli_errno($conn),
'message' => mysqli_error($connection),
'code' => mysqli_errno($connection),
);
}
@@ -151,10 +151,10 @@ class DibiMySqliDriver extends DibiDriver
public function escape($value, $appendQuotes=TRUE)
{
$conn = $this->getResource();
$connection = $this->getConnection();
return $appendQuotes
? "'" . mysqli_real_escape_string($conn, $value) . "'"
: mysqli_real_escape_string($conn, $value);
? "'" . mysqli_real_escape_string($connection, $value) . "'"
: mysqli_real_escape_string($connection, $value);
}

View File

@@ -68,17 +68,17 @@ class DibiOdbcDriver extends DibiDriver
$config = $this->config;
if (empty($config['persistent']))
$conn = @odbc_connect($config['database'], $config['username'], $config['password']);
$connection = @odbc_connect($config['database'], $config['username'], $config['password']);
else
$conn = @odbc_pconnect($config['database'], $config['username'], $config['password']);
$connection = @odbc_pconnect($config['database'], $config['username'], $config['password']);
if (!is_resource($conn))
if (!is_resource($connection))
throw new DibiException("Connecting error (driver odbc)", array(
'message' => odbc_errormsg(),
'code' => odbc_error(),
));
return $conn;
return $connection;
}
@@ -87,12 +87,12 @@ class DibiOdbcDriver extends DibiDriver
{
$this->affectedRows = FALSE;
$conn = $this->getResource();
$res = @odbc_exec($conn, $sql);
$connection = $this->getConnection();
$res = @odbc_exec($connection, $sql);
if ($res === FALSE) return FALSE;
$this->affectedRows = odbc_num_rows($conn);
$this->affectedRows = odbc_num_rows($connection);
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
if (is_resource($res))
@@ -116,34 +116,34 @@ class DibiOdbcDriver extends DibiDriver
public function begin()
{
return odbc_autocommit($this->getResource(), FALSE);
return odbc_autocommit($this->getConnection(), FALSE);
}
public function commit()
{
$conn = $this->getResource();
$ok = odbc_commit($conn);
odbc_autocommit($conn, TRUE);
$connection = $this->getConnection();
$ok = odbc_commit($connection);
odbc_autocommit($connection, TRUE);
return $ok;
}
public function rollback()
{
$conn = $this->getResource();
$ok = odbc_rollback($conn);
odbc_autocommit($conn, TRUE);
$connection = $this->getConnection();
$ok = odbc_rollback($connection);
odbc_autocommit($connection, TRUE);
return $ok;
}
public function errorInfo()
{
$conn = $this->getResource();
$connection = $this->getConnection();
return array(
'message' => odbc_errormsg($conn),
'code' => odbc_error($conn),
'message' => odbc_errormsg($connection),
'code' => odbc_error($connection),
);
}

View File

@@ -66,7 +66,7 @@ class DibiPdoDriver extends DibiDriver
$this->affectedRows = FALSE;
// TODO: or exec() ?
$res = $this->getResource()->query($sql);
$res = $this->getConnection()->query($sql);
if ($res === FALSE) return FALSE;
@@ -85,31 +85,31 @@ class DibiPdoDriver extends DibiDriver
public function insertId()
{
return $this->getResource()->lastInsertId();
return $this->getConnection()->lastInsertId();
}
public function begin()
{
return $this->getResource()->beginTransaction();
return $this->getConnection()->beginTransaction();
}
public function commit()
{
return $this->getResource()->commit();
return $this->getConnection()->commit();
}
public function rollback()
{
return $this->getResource()->rollBack();
return $this->getConnection()->rollBack();
}
public function errorInfo()
{
$error = $this->getResource()->errorInfo();
$error = $this->getConnection()->errorInfo();
return array(
'message' => $error[2],
'code' => $error[1],
@@ -124,7 +124,7 @@ class DibiPdoDriver extends DibiDriver
trigger_error('dibi: escaping without qoutes is not supported by PDO', E_USER_WARNING);
return NULL;
}
return $this->getResource()->quote($value);
return $this->getConnection()->quote($value);
}

View File

@@ -59,20 +59,20 @@ class DibiPostgreDriver extends DibiDriver
$config = $this->config;
if (isset($config['persistent']))
$conn = @pg_connect($config['string'], $config['type']);
$connection = @pg_connect($config['string'], $config['type']);
else
$conn = @pg_pconnect($config['string'], $config['type']);
$connection = @pg_pconnect($config['string'], $config['type']);
if (!is_resource($conn))
if (!is_resource($connection))
throw new DibiException("Connecting error (driver postgre)", array(
'message' => pg_last_error(),
));
if (!empty($config['charset'])) {
@pg_set_client_encoding($conn, $config['charset']);
@pg_set_client_encoding($connection, $config['charset']);
// don't handle this error...
}
return $conn;
return $connection;
}
@@ -81,12 +81,12 @@ class DibiPostgreDriver extends DibiDriver
{
$this->affectedRows = FALSE;
$conn = $this->getResource();
$res = @pg_query($conn, $sql);
$connection = $this->getConnection();
$res = @pg_query($connection, $sql);
if ($res === FALSE) return FALSE;
$this->affectedRows = pg_affected_rows($conn);
$this->affectedRows = pg_affected_rows($connection);
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
if (is_resource($res))
@@ -110,26 +110,26 @@ class DibiPostgreDriver extends DibiDriver
public function begin()
{
return pg_query($this->getResource(), 'BEGIN');
return pg_query($this->getConnection(), 'BEGIN');
}
public function commit()
{
return pg_query($this->getResource(), 'COMMIT');
return pg_query($this->getConnection(), 'COMMIT');
}
public function rollback()
{
return pg_query($this->getResource(), 'ROLLBACK');
return pg_query($this->getConnection(), 'ROLLBACK');
}
public function errorInfo()
{
return array(
'message' => pg_last_error($this->getResource()),
'message' => pg_last_error($this->getConnection()),
'code' => NULL,
);
}

View File

@@ -62,16 +62,16 @@ class DibiSqliteDriver extends DibiDriver
$errorMsg = '';
if (empty($config['persistent']))
$conn = @sqlite_open($config['database'], $config['mode'], $errorMsg);
$connection = @sqlite_open($config['database'], $config['mode'], $errorMsg);
else
$conn = @sqlite_popen($config['database'], $config['mode'], $errorMsg);
$connection = @sqlite_popen($config['database'], $config['mode'], $errorMsg);
if (!$conn)
if (!$connection)
throw new DibiException("Connecting error (driver sqlite)", array(
'message' => $errorMsg,
));
return $conn;
return $connection;
}
@@ -80,15 +80,15 @@ class DibiSqliteDriver extends DibiDriver
{
$this->insertId = $this->affectedRows = FALSE;
$conn = $this->getResource();
$res = @sqlite_query($conn, $sql, SQLITE_ASSOC);
$connection = $this->getConnection();
$res = @sqlite_query($connection, $sql, SQLITE_ASSOC);
if ($res === FALSE) return FALSE;
$this->affectedRows = sqlite_changes($conn);
$this->affectedRows = sqlite_changes($connection);
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
$this->insertId = sqlite_last_insert_rowid($conn);
$this->insertId = sqlite_last_insert_rowid($connection);
if ($this->insertId < 1) $this->insertId = FALSE;
if (is_resource($res))
@@ -112,25 +112,25 @@ class DibiSqliteDriver extends DibiDriver
public function begin()
{
return sqlite_query($this->getResource(), 'BEGIN');
return sqlite_query($this->getConnection(), 'BEGIN');
}
public function commit()
{
return sqlite_query($this->getResource(), 'COMMIT');
return sqlite_query($this->getConnection(), 'COMMIT');
}
public function rollback()
{
return sqlite_query($this->getResource(), 'ROLLBACK');
return sqlite_query($this->getConnection(), 'ROLLBACK');
}
public function errorInfo()
{
$code = sqlite_last_error($this->getResource());
$code = sqlite_last_error($this->getConnection());
return array(
'message' => sqlite_error_string($code),
'code' => $code,

View File

@@ -33,7 +33,7 @@ abstract class DibiDriver
* Connection resource
* @var resource
*/
private $res;
private $connection;
/**
* Describes how convert some datatypes to SQL command
@@ -56,7 +56,7 @@ abstract class DibiDriver
public function __construct($config)
{
$this->config = $config;
if (empty($config['lazy'])) $this->res = $this->connect();
if (empty($config['lazy'])) $this->connection = $this->connect();
}
@@ -86,11 +86,11 @@ abstract class DibiDriver
* Returns the connection resource
* @return resource
*/
public function getResource()
public function getConnection()
{
if (!$this->res) $this->res = $this->connect();
if (!$this->connection) $this->connection = $this->connect();
return $this->res;
return $this->connection;
}
@@ -255,9 +255,9 @@ abstract class DibiDriver
/**
* Access to undeclared property
*/
function __get($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __set($nm, $val) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __unset($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
} // class DibiDriver

View File

@@ -93,7 +93,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
/**
* 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
* @return array|FALSE array on success, FALSE if no next record
*/
abstract protected function doFetch();
@@ -102,23 +102,23 @@ abstract class DibiResult implements IteratorAggregate, Countable
/**
* Fetches the row at current position, process optional type conversion
* and moves the internal cursor to the next position
* @return array|FALSE array() on success, FALSE if no next record
* @return array|FALSE array on success, FALSE if no next record
*/
final public function fetch()
{
$rec = $this->doFetch();
if (!is_array($rec))
$row = $this->doFetch();
if (!is_array($row))
return FALSE;
// types-converting?
if ($t = $this->convert) { // little speed-up
foreach ($rec as $key => $value) {
foreach ($row as $key => $value) {
if (isset($t[$key]))
$rec[$key] = $this->convert($value, $t[$key]);
$row[$key] = $this->convert($value, $t[$key]);
}
}
return $rec;
return $row;
}
@@ -129,20 +129,20 @@ abstract class DibiResult implements IteratorAggregate, Countable
*/
final function fetchSingle()
{
$rec = $this->doFetch();
if (!is_array($rec))
$row = $this->doFetch();
if (!is_array($row))
return FALSE;
// types-converting?
if ($t = $this->convert) { // little speed-up
$value = reset($rec);
$key = key($rec);
$value = reset($row);
$key = key($row);
return isset($t[$key])
? $this->convert($value, $t[$key])
: $value;
}
return reset($rec);
return reset($row);
}
@@ -154,25 +154,25 @@ abstract class DibiResult implements IteratorAggregate, Countable
final function fetchAll()
{
@$this->seek(0);
$rec = $this->fetch();
if (!$rec)
$row = $this->fetch();
if (!$row)
return array(); // empty resultset
$arr = array();
if (count($rec) === 1) {
$key = key($rec);
$data = array();
if (count($row) === 1) {
$key = key($row);
do {
$arr[] = $rec[$key];
} while ($rec = $this->fetch());
$data[] = $row[$key];
} while ($row = $this->fetch());
} else {
do {
$arr[] = $rec;
} while ($rec = $this->fetch());
$data[] = $row;
} while ($row = $this->fetch());
}
return $arr;
return $data;
}
@@ -180,7 +180,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
/**
* Fetches all records from table and returns associative tree
* Associative descriptor: assoc1,*,assoc2,#,assco3
* builds a tree: $arr[value1][index][value2]['assoc3'][value3] = {record}
* builds a tree: $data[value1][index][value2]['assoc3'][value3] = {record}
*
* @param string associative descriptor
* @return array
@@ -188,18 +188,18 @@ abstract class DibiResult implements IteratorAggregate, Countable
final function fetchAssoc($assoc)
{
@$this->seek(0);
$rec = $this->fetch();
if (!$rec) return array(); // empty resultset
$row = $this->fetch();
if (!$row) return array(); // empty resultset
$arr = NULL;
$data = NULL;
$assoc = explode(',', $assoc);
if (count($assoc) === 1) { // speed-up
$as = $assoc[0];
do {
$arr[ $rec[$as] ] = $rec;
} while ($rec = $this->fetch());
return $arr;
$data[ $row[$as] ] = $row;
} while ($row = $this->fetch());
return $data;
}
$last = count($assoc) - 1;
@@ -207,7 +207,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
// make associative tree
do {
$x = & $arr;
$x = & $data;
// iterative deepening
foreach ($assoc as $i => $as) {
@@ -216,7 +216,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
} elseif ($as === '#') { // "record" node
if ($x === NULL) {
$x = $rec;
$x = $row;
$x = & $x[ $assoc[$i+1] ];
$x = NULL; // prepare child node
} else {
@@ -224,16 +224,16 @@ abstract class DibiResult implements IteratorAggregate, Countable
}
} else { // associative-array node
$x = & $x[ $rec[ $as ] ];
$x = & $x[ $row[ $as ] ];
}
}
if ($x === NULL) $x = $rec; // build leaf
if ($x === NULL) $x = $row; // build leaf
} while ($rec = $this->fetch());
} while ($row = $this->fetch());
unset($x);
return $arr;
return $data;
}
@@ -247,38 +247,38 @@ abstract class DibiResult implements IteratorAggregate, Countable
final function fetchPairs($key=NULL, $value=NULL)
{
@$this->seek(0);
$rec = $this->fetch();
if (!$rec) return array(); // empty resultset
$row = $this->fetch();
if (!$row) return array(); // empty resultset
$arr = array();
$data = array();
if ($value === NULL) {
if ($key !== NULL) return FALSE; // error
// autodetect
if (count($rec) < 2) return FALSE;
$tmp = array_keys($rec);
if (count($row) < 2) return FALSE;
$tmp = array_keys($row);
$key = $tmp[0];
$value = $tmp[1];
} else {
if (!array_key_exists($value, $rec)) return FALSE;
if (!array_key_exists($value, $row)) return FALSE;
if ($key === NULL) { // autodetect
do {
$arr[] = $rec[$value];
} while ($rec = $this->fetch());
return $arr;
$data[] = $row[$value];
} while ($row = $this->fetch());
return $data;
}
if (!array_key_exists($key, $rec)) return FALSE;
if (!array_key_exists($key, $row)) return FALSE;
}
do {
$arr[ $rec[$key] ] = $rec[$value];
} while ($rec = $this->fetch());
$data[ $row[$key] ] = $row[$value];
} while ($row = $this->fetch());
return $arr;
return $data;
}
@@ -403,9 +403,9 @@ abstract class DibiResult implements IteratorAggregate, Countable
/**
* Access to undeclared property
*/
function __get($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __set($nm, $val) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __unset($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
} // class DibiResult
@@ -441,8 +441,8 @@ class DibiResultIterator implements Iterator
$result,
$offset,
$count,
$record,
$row;
$row,
$pointer;
public function __construct(DibiResult $result, $offset = NULL, $count = NULL)
@@ -457,38 +457,38 @@ class DibiResultIterator implements Iterator
/** these are the required Iterator functions */
public function rewind()
{
$this->row = 0;
$this->pointer = 0;
@$this->result->seek($this->offset);
$this->record = $this->result->fetch();
$this->row = $this->result->fetch();
}
public function key()
{
return $this->row;
return $this->pointer;
}
public function current()
{
return $this->record;
return $this->row;
}
public function next()
{
$this->record = $this->result->fetch();
$this->row++;
$this->row = $this->result->fetch();
$this->pointer++;
}
public function valid()
{
return is_array($this->record) && ($this->row < $this->count);
return is_array($this->row) && ($this->pointer < $this->count);
}
/** end required Iterator functions */

View File

@@ -380,8 +380,8 @@ class DibiTranslator
/**
* Access to undeclared property
*/
function __get($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __set($nm, $val) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __unset($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
function __get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
} // class DibiParser

View File

@@ -16,12 +16,12 @@ if (!$res) die('SQL error');
// auto-convert this field to integer
$res->setType('customer_id', Dibi::FIELD_INTEGER);
$record = $res->fetch();
var_dump($record);
$row = $res->fetch();
var_dump($row);
// auto-detect all types
// WARNING: THIS WILL NOT WORK WITH SQLITE
$res->setType(TRUE);
$record = $res->fetch();
var_dump($record);
$row = $res->fetch();
var_dump($row);

View File

@@ -18,31 +18,31 @@ dibi::connect(array(
$arr1 = array(1, 2, 3);
$arr2 = array('one', 'two', 'three');
$arr3 = array(
$array1 = array(1, 2, 3);
$array2 = array('one', 'two', 'three');
$array3 = array(
'col1' => 'one',
'col2' => 'two',
'col3' => 'three',
);
$arr4 = array(
$array4 = array(
'a' => 12,
'b' => NULL,
'c%t' => time(), // modifier 'T' means datetime
'd' => 'any string',
);
$arr5 = array('RAND()', '[col1] > [col2]');
$array5 = array('RAND()', '[col1] > [col2]');
dibi::test("
SELECT *
FROM [db.table]
WHERE ([test.a] LIKE %d", '1995-03-01', "
OR [b1] IN (", $arr1, ")
OR [b2] IN (%s", $arr1, ")
OR [b3] IN (", $arr2, ")
OR [b4] IN (%n", $arr3, ")
OR [b5] IN (%sql", $arr5, ")
OR [b1] IN (", $array1, ")
OR [b2] IN (%s", $array1, ")
OR [b3] IN (", $array2, ")
OR [b4] IN (%n", $array3, ")
OR [b5] IN (%sql", $array5, ")
OR [b6] IN (", array(), ")
AND [c] = 'embedded '' string'
OR [d]=%i", 10.3, "
@@ -55,17 +55,17 @@ LIMIT 10");
// dibi detects INSERT or REPLACE command
dibi::test("INSERT INTO [mytable]", $arr4);
dibi::test("INSERT INTO [mytable]", $array4);
// dibi detects MULTI INSERT or REPLACE command
dibi::test("REPLACE INTO [mytable]", $arr4, $arr4, $arr4);
dibi::test("REPLACE INTO [mytable]", $array4, $array4, $array4);
// dibi detects UPDATE command
$n = 123;
dibi::test("UPDATE [mytable] SET", $arr4, " WHERE [id]=%i", $n);
dibi::test("UPDATE [mytable] SET", $array4, " WHERE [id]=%i", $n);
// array with modifier %a - assoc
dibi::test("UPDATE [mytable] SET%a", $arr4, " WHERE [id]=%i", $n);
dibi::test("UPDATE [mytable] SET%a", $array4, " WHERE [id]=%i", $n);