mirror of
https://github.com/dg/dibi.git
synced 2025-08-11 00:24:19 +02:00
* fixed odbc_num_rows and pg_affected_rows
This commit is contained in:
@@ -40,8 +40,9 @@ class DibiMSSqlDriver extends DibiDriver
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
if (!extension_loaded('mssql'))
|
||||
if (!extension_loaded('mssql')) {
|
||||
throw new DibiException("PHP extension 'mssql' is not loaded");
|
||||
}
|
||||
|
||||
if (!isset($config['host'])) $config['host'] = NULL;
|
||||
if (!isset($config['username'])) $config['username'] = NULL;
|
||||
@@ -56,17 +57,18 @@ class DibiMSSqlDriver extends DibiDriver
|
||||
{
|
||||
$config = $this->config;
|
||||
|
||||
if (empty($config['persistent']))
|
||||
if (empty($config['persistent'])) {
|
||||
$connection = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE);
|
||||
else
|
||||
} else {
|
||||
$connection = @mssql_pconnect($config['host'], $config['username'], $config['password']);
|
||||
}
|
||||
|
||||
if (!is_resource($connection))
|
||||
if (!is_resource($connection)) {
|
||||
throw new DibiException("Connecting error (driver mssql)'");
|
||||
}
|
||||
|
||||
if (!empty($config['database'])) {
|
||||
if (!@mssql_select_db($config['database'], $connection))
|
||||
throw new DibiException("Connecting error (driver mssql)");
|
||||
if (!empty($config['database']) && !@mssql_select_db($config['database'], $connection)) {
|
||||
throw new DibiException("Connecting error (driver mssql)");
|
||||
}
|
||||
|
||||
return $connection;
|
||||
@@ -85,8 +87,9 @@ class DibiMSSqlDriver extends DibiDriver
|
||||
$this->affectedRows = mssql_rows_affected($connection);
|
||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||
|
||||
if (is_resource($res))
|
||||
if (is_resource($res)) {
|
||||
return new DibiMSSqlResult($res);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -168,10 +171,13 @@ class DibiMSSqlDriver extends DibiDriver
|
||||
public function applyLimit(&$sql, $limit, $offset = 0)
|
||||
{
|
||||
// offset suppot is missing...
|
||||
if ($limit >= 0)
|
||||
if ($limit >= 0) {
|
||||
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')';
|
||||
}
|
||||
|
||||
if ($offset) throw new DibiException('Offset is not implemented in driver odbc');
|
||||
if ($offset) {
|
||||
throw new DibiException('Offset is not implemented in driver odbc');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -41,8 +41,9 @@ class DibiMySqlDriver extends DibiDriver
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
if (!extension_loaded('mysql'))
|
||||
if (!extension_loaded('mysql')) {
|
||||
throw new DibiException("PHP extension 'mysql' is not loaded");
|
||||
}
|
||||
|
||||
// default values
|
||||
if (empty($config['username'])) $config['username'] = ini_get('mysql.default_user');
|
||||
@@ -62,30 +63,36 @@ class DibiMySqlDriver extends DibiDriver
|
||||
{
|
||||
$config = $this->config;
|
||||
|
||||
if (isset($config['protocol']) && $config['protocol'] === 'unix') // host can be socket
|
||||
if (isset($config['protocol']) && $config['protocol'] === 'unix') { // host can be socket
|
||||
$host = ':' . $config['host'];
|
||||
else
|
||||
} else {
|
||||
$host = $config['host'] . (empty($config['port']) ? '' : ':'.$config['port']);
|
||||
}
|
||||
|
||||
// some errors aren't handled. Must use $php_errormsg
|
||||
if (function_exists('ini_set'))
|
||||
if (function_exists('ini_set')) {
|
||||
$save = ini_set('track_errors', TRUE);
|
||||
}
|
||||
|
||||
$php_errormsg = '';
|
||||
|
||||
if (empty($config['persistent']))
|
||||
if (empty($config['persistent'])) {
|
||||
$connection = @mysql_connect($host, $config['username'], $config['password'], TRUE);
|
||||
else
|
||||
} else {
|
||||
$connection = @mysql_pconnect($host, $config['username'], $config['password']);
|
||||
}
|
||||
|
||||
if (function_exists('ini_set'))
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('track_errors', $save);
|
||||
}
|
||||
|
||||
|
||||
if (!is_resource($connection))
|
||||
if (!is_resource($connection)) {
|
||||
throw new DibiException("Connecting error (driver mysql)'", array(
|
||||
'message' => mysql_error() ? mysql_error() : $php_errormsg,
|
||||
'code' => mysql_errno(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
if (!empty($config['charset'])) {
|
||||
@@ -94,12 +101,11 @@ class DibiMySqlDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
if (!empty($config['database'])) {
|
||||
if (!@mysql_select_db($config['database'], $connection))
|
||||
throw new DibiException("Connecting error (driver mysql)", array(
|
||||
'message' => mysql_error($connection),
|
||||
'code' => mysql_errno($connection),
|
||||
));
|
||||
if (!empty($config['database']) && !@mysql_select_db($config['database'], $connection)) {
|
||||
throw new DibiException("Connecting error (driver mysql)", array(
|
||||
'message' => mysql_error($connection),
|
||||
'code' => mysql_errno($connection),
|
||||
));
|
||||
}
|
||||
|
||||
return $connection;
|
||||
@@ -121,8 +127,9 @@ class DibiMySqlDriver extends DibiDriver
|
||||
$this->insertId = mysql_insert_id($connection);
|
||||
if ($this->insertId < 1) $this->insertId = FALSE;
|
||||
|
||||
if (is_resource($res))
|
||||
if (is_resource($res)) {
|
||||
return new DibiMySqlResult($res);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -309,9 +316,9 @@ class DibiMySqlResult extends DibiResult
|
||||
$info['length'] = mysql_field_len($this->resource, $index);
|
||||
$info['table'] = mysql_field_table($this->resource, $index);
|
||||
|
||||
if (in_array('auto_increment', $info['flags'])) // or 'primary_key' ?
|
||||
if (in_array('auto_increment', $info['flags'])) { // or 'primary_key' ?
|
||||
$info['type'] = dibi::FIELD_COUNTER;
|
||||
else {
|
||||
} else {
|
||||
$info['type'] = isset($types[$native]) ? $types[$native] : dibi::FIELD_UNKNOWN;
|
||||
|
||||
// if ($info['type'] === dibi::FIELD_TEXT && $info['length'] > 255)
|
||||
|
@@ -42,8 +42,9 @@ class DibiMySqliDriver extends DibiDriver
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
if (!extension_loaded('mysqli'))
|
||||
if (!extension_loaded('mysqli')) {
|
||||
throw new DibiException("PHP extension 'mysqli' is not loaded");
|
||||
}
|
||||
|
||||
// default values
|
||||
if (empty($config['username'])) $config['username'] = ini_get('mysqli.default_user');
|
||||
@@ -66,14 +67,16 @@ class DibiMySqliDriver extends DibiDriver
|
||||
|
||||
$connection = @mysqli_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
|
||||
|
||||
if (!$connection)
|
||||
if (!$connection) {
|
||||
throw new DibiException("Connecting error (driver mysqli)", array(
|
||||
'message' => mysqli_connect_error(),
|
||||
'code' => mysqli_connect_errno(),
|
||||
));
|
||||
}
|
||||
|
||||
if (!empty($config['charset']))
|
||||
if (!empty($config['charset'])) {
|
||||
mysqli_query($connection, "SET NAMES '" . $config['charset'] . "'");
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
@@ -94,8 +97,9 @@ class DibiMySqliDriver extends DibiDriver
|
||||
$this->insertId = mysqli_insert_id($connection);
|
||||
if ($this->insertId < 1) $this->insertId = FALSE;
|
||||
|
||||
if (is_object($res))
|
||||
if (is_object($res)) {
|
||||
return new DibiMySqliResult($res);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -278,9 +282,9 @@ class DibiMySqliResult extends DibiResult
|
||||
$info = (array) mysqli_fetch_field_direct($this->resource, $index);
|
||||
$native = $info['native'] = $info['type'];
|
||||
|
||||
if ($info['flags'] & MYSQLI_AUTO_INCREMENT_FLAG) // or 'primary_key' ?
|
||||
if ($info['flags'] & MYSQLI_AUTO_INCREMENT_FLAG) { // or 'primary_key' ?
|
||||
$info['type'] = dibi::FIELD_COUNTER;
|
||||
else {
|
||||
} else {
|
||||
$info['type'] = isset($types[$native]) ? $types[$native] : dibi::FIELD_UNKNOWN;
|
||||
// if ($info['type'] === dibi::FIELD_TEXT && $info['length'] > 255)
|
||||
// $info['type'] = dibi::FIELD_LONG_TEXT;
|
||||
|
@@ -49,14 +49,17 @@ class DibiOdbcDriver extends DibiDriver
|
||||
if (empty($config['password'])) $config['password'] = ini_get('odbc.default_pw');
|
||||
if (empty($config['database'])) $config['database'] = ini_get('odbc.default_db');
|
||||
|
||||
if (empty($config['username']))
|
||||
if (empty($config['username'])) {
|
||||
throw new DibiException("Username must be specified (driver odbc)");
|
||||
}
|
||||
|
||||
if (empty($config['password']))
|
||||
if (empty($config['password'])) {
|
||||
throw new DibiException("Password must be specified (driver odbc)");
|
||||
}
|
||||
|
||||
if (empty($config['database']))
|
||||
if (empty($config['database'])) {
|
||||
throw new DibiException("Database must be specified (driver odbc)");
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
@@ -67,16 +70,18 @@ class DibiOdbcDriver extends DibiDriver
|
||||
{
|
||||
$config = $this->config;
|
||||
|
||||
if (empty($config['persistent']))
|
||||
if (empty($config['persistent'])) {
|
||||
$connection = @odbc_connect($config['database'], $config['username'], $config['password']);
|
||||
else
|
||||
} else {
|
||||
$connection = @odbc_pconnect($config['database'], $config['username'], $config['password']);
|
||||
}
|
||||
|
||||
if (!is_resource($connection))
|
||||
if (!is_resource($connection)) {
|
||||
throw new DibiException("Connecting error (driver odbc)", array(
|
||||
'message' => odbc_errormsg(),
|
||||
'code' => odbc_error(),
|
||||
));
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
@@ -92,11 +97,12 @@ class DibiOdbcDriver extends DibiDriver
|
||||
|
||||
if ($res === FALSE) return FALSE;
|
||||
|
||||
$this->affectedRows = odbc_num_rows($connection);
|
||||
$this->affectedRows = odbc_num_rows($res);
|
||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||
|
||||
if (is_resource($res))
|
||||
if (is_resource($res)) {
|
||||
return new DibiOdbcResult($res);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -185,8 +191,9 @@ class DibiOdbcDriver extends DibiDriver
|
||||
public function applyLimit(&$sql, $limit, $offset = 0)
|
||||
{
|
||||
// offset suppot is missing...
|
||||
if ($limit >= 0)
|
||||
if ($limit >= 0) {
|
||||
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')';
|
||||
}
|
||||
|
||||
if ($offset) throw new DibiException('Offset is not implemented in driver odbc');
|
||||
}
|
||||
@@ -246,8 +253,9 @@ class DibiOdbcResult extends DibiResult
|
||||
protected function buildMeta()
|
||||
{
|
||||
// cache
|
||||
if ($this->meta !== NULL)
|
||||
if ($this->meta !== NULL) {
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
static $types = array(
|
||||
'CHAR' => dibi::FIELD_TEXT,
|
||||
|
@@ -40,11 +40,13 @@ class DibiPdoDriver extends DibiDriver
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
if (!extension_loaded('pdo'))
|
||||
if (!extension_loaded('pdo')) {
|
||||
throw new DibiException("PHP extension 'pdo' is not loaded");
|
||||
}
|
||||
|
||||
if (empty($config['dsn']))
|
||||
if (empty($config['dsn'])) {
|
||||
throw new DibiException("DSN must be specified (driver odbc)");
|
||||
}
|
||||
|
||||
if (empty($config['username'])) $config['username'] = NULL;
|
||||
if (empty($config['password'])) $config['password'] = NULL;
|
||||
@@ -70,8 +72,9 @@ class DibiPdoDriver extends DibiDriver
|
||||
|
||||
if ($res === FALSE) return FALSE;
|
||||
|
||||
if ($res instanceof PDOStatement)
|
||||
if ($res instanceof PDOStatement) {
|
||||
return new DibiPdoResult($res);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -41,11 +41,13 @@ class DibiPostgreDriver extends DibiDriver
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
if (!extension_loaded('pgsql'))
|
||||
if (!extension_loaded('pgsql')) {
|
||||
throw new DibiException("PHP extension 'pgsql' is not loaded");
|
||||
}
|
||||
|
||||
if (empty($config['string']))
|
||||
if (empty($config['string'])) {
|
||||
throw new DibiException("Connection string must be specified (driver postgre)");
|
||||
}
|
||||
|
||||
if (empty($config['type'])) $config['type'] = NULL;
|
||||
|
||||
@@ -58,15 +60,17 @@ class DibiPostgreDriver extends DibiDriver
|
||||
{
|
||||
$config = $this->config;
|
||||
|
||||
if (isset($config['persistent']))
|
||||
if (isset($config['persistent'])) {
|
||||
$connection = @pg_connect($config['string'], $config['type']);
|
||||
else
|
||||
} else {
|
||||
$connection = @pg_pconnect($config['string'], $config['type']);
|
||||
}
|
||||
|
||||
if (!is_resource($connection))
|
||||
if (!is_resource($connection)) {
|
||||
throw new DibiException("Connecting error (driver postgre)", array(
|
||||
'message' => pg_last_error(),
|
||||
));
|
||||
}
|
||||
|
||||
if (!empty($config['charset'])) {
|
||||
@pg_set_client_encoding($connection, $config['charset']);
|
||||
@@ -89,8 +93,9 @@ class DibiPostgreDriver extends DibiDriver
|
||||
$this->affectedRows = pg_affected_rows($connection);
|
||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||
|
||||
if (is_resource($res))
|
||||
if (is_resource($res)) {
|
||||
return new DibiPostgreResult($res);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -42,14 +42,15 @@ class DibiSqliteDriver extends DibiDriver
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
if (!extension_loaded('sqlite'))
|
||||
if (!extension_loaded('sqlite')) {
|
||||
throw new DibiException("PHP extension 'sqlite' is not loaded");
|
||||
}
|
||||
|
||||
if (empty($config['database']))
|
||||
if (empty($config['database'])) {
|
||||
throw new DibiException("Database must be specified (driver sqlite)");
|
||||
}
|
||||
|
||||
if (!isset($config['mode']))
|
||||
$config['mode'] = 0666;
|
||||
if (!isset($config['mode'])) $config['mode'] = 0666;
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
@@ -61,15 +62,17 @@ class DibiSqliteDriver extends DibiDriver
|
||||
$config = $this->config;
|
||||
|
||||
$errorMsg = '';
|
||||
if (empty($config['persistent']))
|
||||
if (empty($config['persistent'])) {
|
||||
$connection = @sqlite_open($config['database'], $config['mode'], $errorMsg);
|
||||
else
|
||||
} else {
|
||||
$connection = @sqlite_popen($config['database'], $config['mode'], $errorMsg);
|
||||
}
|
||||
|
||||
if (!$connection)
|
||||
if (!$connection) {
|
||||
throw new DibiException("Connecting error (driver sqlite)", array(
|
||||
'message' => $errorMsg,
|
||||
));
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
@@ -91,8 +94,9 @@ class DibiSqliteDriver extends DibiDriver
|
||||
$this->insertId = sqlite_last_insert_rowid($connection);
|
||||
if ($this->insertId < 1) $this->insertId = FALSE;
|
||||
|
||||
if (is_resource($res))
|
||||
if (is_resource($res)) {
|
||||
return new DibiSqliteResult($res);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user