mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
* some variables renamed
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
* with this package in the file license.txt.
|
* with this package in the file license.txt.
|
||||||
*
|
*
|
||||||
* @author David Grudl
|
* @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
|
* @license New BSD License
|
||||||
* @version 0.8d (Revision: $WCREV$, Date: $WCDATE$)
|
* @version 0.8d (Revision: $WCREV$, Date: $WCDATE$)
|
||||||
* @category Database
|
* @category Database
|
||||||
@@ -100,7 +100,7 @@ class dibi
|
|||||||
* Current connection
|
* Current connection
|
||||||
* @var DibiDriver
|
* @var DibiDriver
|
||||||
*/
|
*/
|
||||||
static private $conn;
|
static private $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last SQL command @see dibi::query()
|
* Last SQL command @see dibi::query()
|
||||||
@@ -175,12 +175,12 @@ class dibi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create connection object and store in list
|
// create connection object and store in list
|
||||||
/** like $conn = $className::connect($config); */
|
/** like $connection = $className::connect($config); */
|
||||||
self::$conn = self::$registry[$name] = new $className($config);
|
self::$connection = self::$registry[$name] = new $className($config);
|
||||||
|
|
||||||
if (dibi::$logAll) dibi::log("OK: connected to DB '$config[driver]'");
|
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()
|
static public function isConnected()
|
||||||
{
|
{
|
||||||
return (bool) self::$conn;
|
return (bool) self::$connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -206,10 +206,10 @@ class dibi
|
|||||||
static public function getConnection($name=NULL)
|
static public function getConnection($name=NULL)
|
||||||
{
|
{
|
||||||
if ($name === NULL) {
|
if ($name === NULL) {
|
||||||
if (!self::$conn)
|
if (!self::$connection)
|
||||||
throw new DibiException('Dibi is not connected to database');
|
throw new DibiException('Dibi is not connected to database');
|
||||||
|
|
||||||
return self::$conn;
|
return self::$connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(self::$registry[$name]))
|
if (!isset(self::$registry[$name]))
|
||||||
@@ -229,7 +229,7 @@ class dibi
|
|||||||
*/
|
*/
|
||||||
static public function activate($name)
|
static public function activate($name)
|
||||||
{
|
{
|
||||||
self::$conn = self::getConnection($name);
|
self::$connection = self::getConnection($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -57,19 +57,19 @@ class DibiMSSqlDriver extends DibiDriver
|
|||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
|
|
||||||
if (empty($config['persistent']))
|
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
|
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)'");
|
throw new DibiException("Connecting error (driver mssql)'");
|
||||||
|
|
||||||
if (!empty($config['database'])) {
|
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)");
|
throw new DibiException("Connecting error (driver mssql)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $conn;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -78,12 +78,12 @@ class DibiMSSqlDriver extends DibiDriver
|
|||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->affectedRows = FALSE;
|
$this->affectedRows = FALSE;
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$res = @mssql_query($sql, $conn);
|
$res = @mssql_query($sql, $connection);
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
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 ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||||
|
|
||||||
if (is_resource($res))
|
if (is_resource($res))
|
||||||
@@ -107,19 +107,19 @@ class DibiMSSqlDriver extends DibiDriver
|
|||||||
|
|
||||||
public function begin()
|
public function begin()
|
||||||
{
|
{
|
||||||
return mssql_query('BEGIN TRANSACTION', $this->getResource());
|
return mssql_query('BEGIN TRANSACTION', $this->getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
return mssql_query('COMMIT', $this->getResource());
|
return mssql_query('COMMIT', $this->getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
return mssql_query('ROLLBACK', $this->getResource());
|
return mssql_query('ROLLBACK', $this->getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -73,15 +73,15 @@ class DibiMySqlDriver extends DibiDriver
|
|||||||
$php_errormsg = '';
|
$php_errormsg = '';
|
||||||
|
|
||||||
if (empty($config['persistent']))
|
if (empty($config['persistent']))
|
||||||
$conn = @mysql_connect($host, $config['username'], $config['password'], TRUE);
|
$connection = @mysql_connect($host, $config['username'], $config['password'], TRUE);
|
||||||
else
|
else
|
||||||
$conn = @mysql_pconnect($host, $config['username'], $config['password']);
|
$connection = @mysql_pconnect($host, $config['username'], $config['password']);
|
||||||
|
|
||||||
if (function_exists('ini_set'))
|
if (function_exists('ini_set'))
|
||||||
ini_set('track_errors', $save);
|
ini_set('track_errors', $save);
|
||||||
|
|
||||||
|
|
||||||
if (!is_resource($conn))
|
if (!is_resource($connection))
|
||||||
throw new DibiException("Connecting error (driver mysql)'", array(
|
throw new DibiException("Connecting error (driver mysql)'", array(
|
||||||
'message' => mysql_error() ? mysql_error() : $php_errormsg,
|
'message' => mysql_error() ? mysql_error() : $php_errormsg,
|
||||||
'code' => mysql_errno(),
|
'code' => mysql_errno(),
|
||||||
@@ -89,20 +89,20 @@ class DibiMySqlDriver extends DibiDriver
|
|||||||
|
|
||||||
|
|
||||||
if (!empty($config['charset'])) {
|
if (!empty($config['charset'])) {
|
||||||
@mysql_query("SET NAMES '" . $config['charset'] . "'", $conn);
|
@mysql_query("SET NAMES '" . $config['charset'] . "'", $connection);
|
||||||
// don't handle this error...
|
// don't handle this error...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!empty($config['database'])) {
|
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(
|
throw new DibiException("Connecting error (driver mysql)", array(
|
||||||
'message' => mysql_error($conn),
|
'message' => mysql_error($connection),
|
||||||
'code' => mysql_errno($conn),
|
'code' => mysql_errno($connection),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $conn;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,15 +111,15 @@ class DibiMySqlDriver extends DibiDriver
|
|||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->insertId = $this->affectedRows = FALSE;
|
$this->insertId = $this->affectedRows = FALSE;
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$res = @mysql_query($sql, $conn);
|
$res = @mysql_query($sql, $connection);
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) return FALSE;
|
||||||
|
|
||||||
$this->affectedRows = mysql_affected_rows($conn);
|
$this->affectedRows = mysql_affected_rows($connection);
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
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 ($this->insertId < 1) $this->insertId = FALSE;
|
||||||
|
|
||||||
if (is_resource($res))
|
if (is_resource($res))
|
||||||
@@ -143,38 +143,38 @@ class DibiMySqlDriver extends DibiDriver
|
|||||||
|
|
||||||
public function begin()
|
public function begin()
|
||||||
{
|
{
|
||||||
return mysql_query('BEGIN', $this->getResource());
|
return mysql_query('BEGIN', $this->getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
return mysql_query('COMMIT', $this->getResource());
|
return mysql_query('COMMIT', $this->getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
return mysql_query('ROLLBACK', $this->getResource());
|
return mysql_query('ROLLBACK', $this->getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function errorInfo()
|
public function errorInfo()
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
return array(
|
return array(
|
||||||
'message' => mysql_error($conn),
|
'message' => mysql_error($connection),
|
||||||
'code' => mysql_errno($conn),
|
'code' => mysql_errno($connection),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function escape($value, $appendQuotes=TRUE)
|
public function escape($value, $appendQuotes=TRUE)
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
return $appendQuotes
|
return $appendQuotes
|
||||||
? "'" . mysql_real_escape_string($value, $conn) . "'"
|
? "'" . mysql_real_escape_string($value, $connection) . "'"
|
||||||
: mysql_real_escape_string($value, $conn);
|
: mysql_real_escape_string($value, $connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -64,18 +64,18 @@ class DibiMySqliDriver extends DibiDriver
|
|||||||
{
|
{
|
||||||
$config = $this->config;
|
$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(
|
throw new DibiException("Connecting error (driver mysqli)", array(
|
||||||
'message' => mysqli_connect_error(),
|
'message' => mysqli_connect_error(),
|
||||||
'code' => mysqli_connect_errno(),
|
'code' => mysqli_connect_errno(),
|
||||||
));
|
));
|
||||||
|
|
||||||
if (!empty($config['charset']))
|
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)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->insertId = $this->affectedRows = FALSE;
|
$this->insertId = $this->affectedRows = FALSE;
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$res = @mysqli_query($conn, $sql);
|
$res = @mysqli_query($connection, $sql);
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) return FALSE;
|
||||||
|
|
||||||
$this->affectedRows = mysqli_affected_rows($conn);
|
$this->affectedRows = mysqli_affected_rows($connection);
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
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 ($this->insertId < 1) $this->insertId = FALSE;
|
||||||
|
|
||||||
if (is_object($res))
|
if (is_object($res))
|
||||||
@@ -115,34 +115,34 @@ class DibiMySqliDriver extends DibiDriver
|
|||||||
|
|
||||||
public function begin()
|
public function begin()
|
||||||
{
|
{
|
||||||
return mysqli_autocommit($this->getResource(), FALSE);
|
return mysqli_autocommit($this->getConnection(), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$ok = mysqli_commit($conn);
|
$ok = mysqli_commit($connection);
|
||||||
mysqli_autocommit($conn, TRUE);
|
mysqli_autocommit($connection, TRUE);
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$ok = mysqli_rollback($conn);
|
$ok = mysqli_rollback($connection);
|
||||||
mysqli_autocommit($conn, TRUE);
|
mysqli_autocommit($connection, TRUE);
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function errorInfo()
|
public function errorInfo()
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
return array(
|
return array(
|
||||||
'message' => mysqli_error($conn),
|
'message' => mysqli_error($connection),
|
||||||
'code' => mysqli_errno($conn),
|
'code' => mysqli_errno($connection),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,10 +151,10 @@ class DibiMySqliDriver extends DibiDriver
|
|||||||
|
|
||||||
public function escape($value, $appendQuotes=TRUE)
|
public function escape($value, $appendQuotes=TRUE)
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
return $appendQuotes
|
return $appendQuotes
|
||||||
? "'" . mysqli_real_escape_string($conn, $value) . "'"
|
? "'" . mysqli_real_escape_string($connection, $value) . "'"
|
||||||
: mysqli_real_escape_string($conn, $value);
|
: mysqli_real_escape_string($connection, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -68,17 +68,17 @@ class DibiOdbcDriver extends DibiDriver
|
|||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
|
|
||||||
if (empty($config['persistent']))
|
if (empty($config['persistent']))
|
||||||
$conn = @odbc_connect($config['database'], $config['username'], $config['password']);
|
$connection = @odbc_connect($config['database'], $config['username'], $config['password']);
|
||||||
else
|
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(
|
throw new DibiException("Connecting error (driver odbc)", array(
|
||||||
'message' => odbc_errormsg(),
|
'message' => odbc_errormsg(),
|
||||||
'code' => odbc_error(),
|
'code' => odbc_error(),
|
||||||
));
|
));
|
||||||
|
|
||||||
return $conn;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,12 +87,12 @@ class DibiOdbcDriver extends DibiDriver
|
|||||||
{
|
{
|
||||||
$this->affectedRows = FALSE;
|
$this->affectedRows = FALSE;
|
||||||
|
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$res = @odbc_exec($conn, $sql);
|
$res = @odbc_exec($connection, $sql);
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
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 ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||||
|
|
||||||
if (is_resource($res))
|
if (is_resource($res))
|
||||||
@@ -116,34 +116,34 @@ class DibiOdbcDriver extends DibiDriver
|
|||||||
|
|
||||||
public function begin()
|
public function begin()
|
||||||
{
|
{
|
||||||
return odbc_autocommit($this->getResource(), FALSE);
|
return odbc_autocommit($this->getConnection(), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$ok = odbc_commit($conn);
|
$ok = odbc_commit($connection);
|
||||||
odbc_autocommit($conn, TRUE);
|
odbc_autocommit($connection, TRUE);
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$ok = odbc_rollback($conn);
|
$ok = odbc_rollback($connection);
|
||||||
odbc_autocommit($conn, TRUE);
|
odbc_autocommit($connection, TRUE);
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function errorInfo()
|
public function errorInfo()
|
||||||
{
|
{
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
return array(
|
return array(
|
||||||
'message' => odbc_errormsg($conn),
|
'message' => odbc_errormsg($connection),
|
||||||
'code' => odbc_error($conn),
|
'code' => odbc_error($connection),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,7 +66,7 @@ class DibiPdoDriver extends DibiDriver
|
|||||||
$this->affectedRows = FALSE;
|
$this->affectedRows = FALSE;
|
||||||
|
|
||||||
// TODO: or exec() ?
|
// TODO: or exec() ?
|
||||||
$res = $this->getResource()->query($sql);
|
$res = $this->getConnection()->query($sql);
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) return FALSE;
|
||||||
|
|
||||||
@@ -85,31 +85,31 @@ class DibiPdoDriver extends DibiDriver
|
|||||||
|
|
||||||
public function insertId()
|
public function insertId()
|
||||||
{
|
{
|
||||||
return $this->getResource()->lastInsertId();
|
return $this->getConnection()->lastInsertId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function begin()
|
public function begin()
|
||||||
{
|
{
|
||||||
return $this->getResource()->beginTransaction();
|
return $this->getConnection()->beginTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
return $this->getResource()->commit();
|
return $this->getConnection()->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
return $this->getResource()->rollBack();
|
return $this->getConnection()->rollBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function errorInfo()
|
public function errorInfo()
|
||||||
{
|
{
|
||||||
$error = $this->getResource()->errorInfo();
|
$error = $this->getConnection()->errorInfo();
|
||||||
return array(
|
return array(
|
||||||
'message' => $error[2],
|
'message' => $error[2],
|
||||||
'code' => $error[1],
|
'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);
|
trigger_error('dibi: escaping without qoutes is not supported by PDO', E_USER_WARNING);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return $this->getResource()->quote($value);
|
return $this->getConnection()->quote($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -59,20 +59,20 @@ class DibiPostgreDriver extends DibiDriver
|
|||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
|
|
||||||
if (isset($config['persistent']))
|
if (isset($config['persistent']))
|
||||||
$conn = @pg_connect($config['string'], $config['type']);
|
$connection = @pg_connect($config['string'], $config['type']);
|
||||||
else
|
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(
|
throw new DibiException("Connecting error (driver postgre)", array(
|
||||||
'message' => pg_last_error(),
|
'message' => pg_last_error(),
|
||||||
));
|
));
|
||||||
|
|
||||||
if (!empty($config['charset'])) {
|
if (!empty($config['charset'])) {
|
||||||
@pg_set_client_encoding($conn, $config['charset']);
|
@pg_set_client_encoding($connection, $config['charset']);
|
||||||
// don't handle this error...
|
// don't handle this error...
|
||||||
}
|
}
|
||||||
return $conn;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,12 +81,12 @@ class DibiPostgreDriver extends DibiDriver
|
|||||||
{
|
{
|
||||||
$this->affectedRows = FALSE;
|
$this->affectedRows = FALSE;
|
||||||
|
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$res = @pg_query($conn, $sql);
|
$res = @pg_query($connection, $sql);
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
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 ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||||
|
|
||||||
if (is_resource($res))
|
if (is_resource($res))
|
||||||
@@ -110,26 +110,26 @@ class DibiPostgreDriver extends DibiDriver
|
|||||||
|
|
||||||
public function begin()
|
public function begin()
|
||||||
{
|
{
|
||||||
return pg_query($this->getResource(), 'BEGIN');
|
return pg_query($this->getConnection(), 'BEGIN');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
return pg_query($this->getResource(), 'COMMIT');
|
return pg_query($this->getConnection(), 'COMMIT');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
return pg_query($this->getResource(), 'ROLLBACK');
|
return pg_query($this->getConnection(), 'ROLLBACK');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function errorInfo()
|
public function errorInfo()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'message' => pg_last_error($this->getResource()),
|
'message' => pg_last_error($this->getConnection()),
|
||||||
'code' => NULL,
|
'code' => NULL,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -62,16 +62,16 @@ class DibiSqliteDriver extends DibiDriver
|
|||||||
|
|
||||||
$errorMsg = '';
|
$errorMsg = '';
|
||||||
if (empty($config['persistent']))
|
if (empty($config['persistent']))
|
||||||
$conn = @sqlite_open($config['database'], $config['mode'], $errorMsg);
|
$connection = @sqlite_open($config['database'], $config['mode'], $errorMsg);
|
||||||
else
|
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(
|
throw new DibiException("Connecting error (driver sqlite)", array(
|
||||||
'message' => $errorMsg,
|
'message' => $errorMsg,
|
||||||
));
|
));
|
||||||
|
|
||||||
return $conn;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -80,15 +80,15 @@ class DibiSqliteDriver extends DibiDriver
|
|||||||
{
|
{
|
||||||
$this->insertId = $this->affectedRows = FALSE;
|
$this->insertId = $this->affectedRows = FALSE;
|
||||||
|
|
||||||
$conn = $this->getResource();
|
$connection = $this->getConnection();
|
||||||
$res = @sqlite_query($conn, $sql, SQLITE_ASSOC);
|
$res = @sqlite_query($connection, $sql, SQLITE_ASSOC);
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) return FALSE;
|
||||||
|
|
||||||
$this->affectedRows = sqlite_changes($conn);
|
$this->affectedRows = sqlite_changes($connection);
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
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 ($this->insertId < 1) $this->insertId = FALSE;
|
||||||
|
|
||||||
if (is_resource($res))
|
if (is_resource($res))
|
||||||
@@ -112,25 +112,25 @@ class DibiSqliteDriver extends DibiDriver
|
|||||||
|
|
||||||
public function begin()
|
public function begin()
|
||||||
{
|
{
|
||||||
return sqlite_query($this->getResource(), 'BEGIN');
|
return sqlite_query($this->getConnection(), 'BEGIN');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
return sqlite_query($this->getResource(), 'COMMIT');
|
return sqlite_query($this->getConnection(), 'COMMIT');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
return sqlite_query($this->getResource(), 'ROLLBACK');
|
return sqlite_query($this->getConnection(), 'ROLLBACK');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function errorInfo()
|
public function errorInfo()
|
||||||
{
|
{
|
||||||
$code = sqlite_last_error($this->getResource());
|
$code = sqlite_last_error($this->getConnection());
|
||||||
return array(
|
return array(
|
||||||
'message' => sqlite_error_string($code),
|
'message' => sqlite_error_string($code),
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
|
@@ -33,7 +33,7 @@ abstract class DibiDriver
|
|||||||
* Connection resource
|
* Connection resource
|
||||||
* @var resource
|
* @var resource
|
||||||
*/
|
*/
|
||||||
private $res;
|
private $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes how convert some datatypes to SQL command
|
* Describes how convert some datatypes to SQL command
|
||||||
@@ -56,7 +56,7 @@ abstract class DibiDriver
|
|||||||
public function __construct($config)
|
public function __construct($config)
|
||||||
{
|
{
|
||||||
$this->config = $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
|
* Returns the connection resource
|
||||||
* @return 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
|
* Access to undeclared property
|
||||||
*/
|
*/
|
||||||
function __get($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($nm, $val) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
|
function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||||
function __unset($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
|
function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||||
|
|
||||||
|
|
||||||
} // class DibiDriver
|
} // class DibiDriver
|
||||||
|
@@ -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
|
* Fetches the row at current position and moves the internal cursor to the next position
|
||||||
* internal usage only
|
* 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();
|
abstract protected function doFetch();
|
||||||
|
|
||||||
@@ -102,23 +102,23 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
|||||||
/**
|
/**
|
||||||
* Fetches the row at current position, process optional type conversion
|
* Fetches the row at current position, process optional type conversion
|
||||||
* and moves the internal cursor to the next position
|
* 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()
|
final public function fetch()
|
||||||
{
|
{
|
||||||
$rec = $this->doFetch();
|
$row = $this->doFetch();
|
||||||
if (!is_array($rec))
|
if (!is_array($row))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// types-converting?
|
// types-converting?
|
||||||
if ($t = $this->convert) { // little speed-up
|
if ($t = $this->convert) { // little speed-up
|
||||||
foreach ($rec as $key => $value) {
|
foreach ($row as $key => $value) {
|
||||||
if (isset($t[$key]))
|
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()
|
final function fetchSingle()
|
||||||
{
|
{
|
||||||
$rec = $this->doFetch();
|
$row = $this->doFetch();
|
||||||
if (!is_array($rec))
|
if (!is_array($row))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// types-converting?
|
// types-converting?
|
||||||
if ($t = $this->convert) { // little speed-up
|
if ($t = $this->convert) { // little speed-up
|
||||||
$value = reset($rec);
|
$value = reset($row);
|
||||||
$key = key($rec);
|
$key = key($row);
|
||||||
return isset($t[$key])
|
return isset($t[$key])
|
||||||
? $this->convert($value, $t[$key])
|
? $this->convert($value, $t[$key])
|
||||||
: $value;
|
: $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return reset($rec);
|
return reset($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -154,25 +154,25 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
|||||||
final function fetchAll()
|
final function fetchAll()
|
||||||
{
|
{
|
||||||
@$this->seek(0);
|
@$this->seek(0);
|
||||||
$rec = $this->fetch();
|
$row = $this->fetch();
|
||||||
if (!$rec)
|
if (!$row)
|
||||||
return array(); // empty resultset
|
return array(); // empty resultset
|
||||||
|
|
||||||
$arr = array();
|
$data = array();
|
||||||
if (count($rec) === 1) {
|
if (count($row) === 1) {
|
||||||
$key = key($rec);
|
$key = key($row);
|
||||||
do {
|
do {
|
||||||
$arr[] = $rec[$key];
|
$data[] = $row[$key];
|
||||||
} while ($rec = $this->fetch());
|
} while ($row = $this->fetch());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$arr[] = $rec;
|
$data[] = $row;
|
||||||
} while ($rec = $this->fetch());
|
} 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
|
* Fetches all records from table and returns associative tree
|
||||||
* Associative descriptor: assoc1,*,assoc2,#,assco3
|
* 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
|
* @param string associative descriptor
|
||||||
* @return array
|
* @return array
|
||||||
@@ -188,18 +188,18 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
|||||||
final function fetchAssoc($assoc)
|
final function fetchAssoc($assoc)
|
||||||
{
|
{
|
||||||
@$this->seek(0);
|
@$this->seek(0);
|
||||||
$rec = $this->fetch();
|
$row = $this->fetch();
|
||||||
if (!$rec) return array(); // empty resultset
|
if (!$row) return array(); // empty resultset
|
||||||
|
|
||||||
$arr = NULL;
|
$data = NULL;
|
||||||
$assoc = explode(',', $assoc);
|
$assoc = explode(',', $assoc);
|
||||||
|
|
||||||
if (count($assoc) === 1) { // speed-up
|
if (count($assoc) === 1) { // speed-up
|
||||||
$as = $assoc[0];
|
$as = $assoc[0];
|
||||||
do {
|
do {
|
||||||
$arr[ $rec[$as] ] = $rec;
|
$data[ $row[$as] ] = $row;
|
||||||
} while ($rec = $this->fetch());
|
} while ($row = $this->fetch());
|
||||||
return $arr;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
$last = count($assoc) - 1;
|
$last = count($assoc) - 1;
|
||||||
@@ -207,7 +207,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
|||||||
|
|
||||||
// make associative tree
|
// make associative tree
|
||||||
do {
|
do {
|
||||||
$x = & $arr;
|
$x = & $data;
|
||||||
|
|
||||||
// iterative deepening
|
// iterative deepening
|
||||||
foreach ($assoc as $i => $as) {
|
foreach ($assoc as $i => $as) {
|
||||||
@@ -216,7 +216,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
|||||||
|
|
||||||
} elseif ($as === '#') { // "record" node
|
} elseif ($as === '#') { // "record" node
|
||||||
if ($x === NULL) {
|
if ($x === NULL) {
|
||||||
$x = $rec;
|
$x = $row;
|
||||||
$x = & $x[ $assoc[$i+1] ];
|
$x = & $x[ $assoc[$i+1] ];
|
||||||
$x = NULL; // prepare child node
|
$x = NULL; // prepare child node
|
||||||
} else {
|
} else {
|
||||||
@@ -224,16 +224,16 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else { // associative-array node
|
} 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);
|
unset($x);
|
||||||
return $arr;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -247,38 +247,38 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
|||||||
final function fetchPairs($key=NULL, $value=NULL)
|
final function fetchPairs($key=NULL, $value=NULL)
|
||||||
{
|
{
|
||||||
@$this->seek(0);
|
@$this->seek(0);
|
||||||
$rec = $this->fetch();
|
$row = $this->fetch();
|
||||||
if (!$rec) return array(); // empty resultset
|
if (!$row) return array(); // empty resultset
|
||||||
|
|
||||||
$arr = array();
|
$data = array();
|
||||||
|
|
||||||
if ($value === NULL) {
|
if ($value === NULL) {
|
||||||
if ($key !== NULL) return FALSE; // error
|
if ($key !== NULL) return FALSE; // error
|
||||||
|
|
||||||
// autodetect
|
// autodetect
|
||||||
if (count($rec) < 2) return FALSE;
|
if (count($row) < 2) return FALSE;
|
||||||
$tmp = array_keys($rec);
|
$tmp = array_keys($row);
|
||||||
$key = $tmp[0];
|
$key = $tmp[0];
|
||||||
$value = $tmp[1];
|
$value = $tmp[1];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!array_key_exists($value, $rec)) return FALSE;
|
if (!array_key_exists($value, $row)) return FALSE;
|
||||||
|
|
||||||
if ($key === NULL) { // autodetect
|
if ($key === NULL) { // autodetect
|
||||||
do {
|
do {
|
||||||
$arr[] = $rec[$value];
|
$data[] = $row[$value];
|
||||||
} while ($rec = $this->fetch());
|
} while ($row = $this->fetch());
|
||||||
return $arr;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists($key, $rec)) return FALSE;
|
if (!array_key_exists($key, $row)) return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$arr[ $rec[$key] ] = $rec[$value];
|
$data[ $row[$key] ] = $row[$value];
|
||||||
} while ($rec = $this->fetch());
|
} while ($row = $this->fetch());
|
||||||
|
|
||||||
return $arr;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -403,9 +403,9 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
|||||||
/**
|
/**
|
||||||
* Access to undeclared property
|
* Access to undeclared property
|
||||||
*/
|
*/
|
||||||
function __get($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($nm, $val) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
|
function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||||
function __unset($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
|
function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||||
|
|
||||||
} // class DibiResult
|
} // class DibiResult
|
||||||
|
|
||||||
@@ -441,8 +441,8 @@ class DibiResultIterator implements Iterator
|
|||||||
$result,
|
$result,
|
||||||
$offset,
|
$offset,
|
||||||
$count,
|
$count,
|
||||||
$record,
|
$row,
|
||||||
$row;
|
$pointer;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(DibiResult $result, $offset = NULL, $count = NULL)
|
public function __construct(DibiResult $result, $offset = NULL, $count = NULL)
|
||||||
@@ -457,38 +457,38 @@ class DibiResultIterator implements Iterator
|
|||||||
/** these are the required Iterator functions */
|
/** these are the required Iterator functions */
|
||||||
public function rewind()
|
public function rewind()
|
||||||
{
|
{
|
||||||
$this->row = 0;
|
$this->pointer = 0;
|
||||||
@$this->result->seek($this->offset);
|
@$this->result->seek($this->offset);
|
||||||
$this->record = $this->result->fetch();
|
$this->row = $this->result->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function key()
|
public function key()
|
||||||
{
|
{
|
||||||
return $this->row;
|
return $this->pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function current()
|
public function current()
|
||||||
{
|
{
|
||||||
return $this->record;
|
return $this->row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function next()
|
public function next()
|
||||||
{
|
{
|
||||||
$this->record = $this->result->fetch();
|
$this->row = $this->result->fetch();
|
||||||
$this->row++;
|
$this->pointer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function valid()
|
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 */
|
/** end required Iterator functions */
|
||||||
|
|
||||||
|
@@ -380,8 +380,8 @@ class DibiTranslator
|
|||||||
/**
|
/**
|
||||||
* Access to undeclared property
|
* Access to undeclared property
|
||||||
*/
|
*/
|
||||||
function __get($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($nm, $val) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
|
function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||||
function __unset($nm) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$nm"); }
|
function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||||
|
|
||||||
} // class DibiParser
|
} // class DibiParser
|
||||||
|
@@ -16,12 +16,12 @@ if (!$res) die('SQL error');
|
|||||||
|
|
||||||
// auto-convert this field to integer
|
// auto-convert this field to integer
|
||||||
$res->setType('customer_id', Dibi::FIELD_INTEGER);
|
$res->setType('customer_id', Dibi::FIELD_INTEGER);
|
||||||
$record = $res->fetch();
|
$row = $res->fetch();
|
||||||
var_dump($record);
|
var_dump($row);
|
||||||
|
|
||||||
|
|
||||||
// auto-detect all types
|
// auto-detect all types
|
||||||
// WARNING: THIS WILL NOT WORK WITH SQLITE
|
// WARNING: THIS WILL NOT WORK WITH SQLITE
|
||||||
$res->setType(TRUE);
|
$res->setType(TRUE);
|
||||||
$record = $res->fetch();
|
$row = $res->fetch();
|
||||||
var_dump($record);
|
var_dump($row);
|
||||||
|
@@ -18,31 +18,31 @@ dibi::connect(array(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
$arr1 = array(1, 2, 3);
|
$array1 = array(1, 2, 3);
|
||||||
$arr2 = array('one', 'two', 'three');
|
$array2 = array('one', 'two', 'three');
|
||||||
$arr3 = array(
|
$array3 = array(
|
||||||
'col1' => 'one',
|
'col1' => 'one',
|
||||||
'col2' => 'two',
|
'col2' => 'two',
|
||||||
'col3' => 'three',
|
'col3' => 'three',
|
||||||
);
|
);
|
||||||
$arr4 = array(
|
$array4 = array(
|
||||||
'a' => 12,
|
'a' => 12,
|
||||||
'b' => NULL,
|
'b' => NULL,
|
||||||
'c%t' => time(), // modifier 'T' means datetime
|
'c%t' => time(), // modifier 'T' means datetime
|
||||||
'd' => 'any string',
|
'd' => 'any string',
|
||||||
);
|
);
|
||||||
$arr5 = array('RAND()', '[col1] > [col2]');
|
$array5 = array('RAND()', '[col1] > [col2]');
|
||||||
|
|
||||||
|
|
||||||
dibi::test("
|
dibi::test("
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM [db.table]
|
FROM [db.table]
|
||||||
WHERE ([test.a] LIKE %d", '1995-03-01', "
|
WHERE ([test.a] LIKE %d", '1995-03-01', "
|
||||||
OR [b1] IN (", $arr1, ")
|
OR [b1] IN (", $array1, ")
|
||||||
OR [b2] IN (%s", $arr1, ")
|
OR [b2] IN (%s", $array1, ")
|
||||||
OR [b3] IN (", $arr2, ")
|
OR [b3] IN (", $array2, ")
|
||||||
OR [b4] IN (%n", $arr3, ")
|
OR [b4] IN (%n", $array3, ")
|
||||||
OR [b5] IN (%sql", $arr5, ")
|
OR [b5] IN (%sql", $array5, ")
|
||||||
OR [b6] IN (", array(), ")
|
OR [b6] IN (", array(), ")
|
||||||
AND [c] = 'embedded '' string'
|
AND [c] = 'embedded '' string'
|
||||||
OR [d]=%i", 10.3, "
|
OR [d]=%i", 10.3, "
|
||||||
@@ -55,17 +55,17 @@ LIMIT 10");
|
|||||||
|
|
||||||
|
|
||||||
// dibi detects INSERT or REPLACE command
|
// 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 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
|
// dibi detects UPDATE command
|
||||||
$n = 123;
|
$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
|
// 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);
|
||||||
|
Reference in New Issue
Block a user