mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 21:28:02 +02:00
* removed variables $insertId & $affectedRows
This commit is contained in:
@@ -22,9 +22,6 @@ if (!class_exists('dibi', FALSE)) die();
|
|||||||
*/
|
*/
|
||||||
class DibiMSSqlDriver extends DibiDriver
|
class DibiMSSqlDriver extends DibiDriver
|
||||||
{
|
{
|
||||||
private
|
|
||||||
$affectedRows = FALSE;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
$formats = array(
|
$formats = array(
|
||||||
'TRUE' => "1",
|
'TRUE' => "1",
|
||||||
@@ -78,27 +75,25 @@ class DibiMSSqlDriver extends DibiDriver
|
|||||||
|
|
||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->affectedRows = FALSE;
|
$res = @mssql_query($sql, $this->getConnection());
|
||||||
$connection = $this->getConnection();
|
|
||||||
$res = @mssql_query($sql, $connection);
|
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) {
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
$this->affectedRows = mssql_rows_affected($connection);
|
} elseif (is_resource($res)) {
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
|
||||||
|
|
||||||
if (is_resource($res)) {
|
|
||||||
return new DibiMSSqlResult($res);
|
return new DibiMSSqlResult($res);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
} else {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
return $this->affectedRows;
|
$rows = mssql_rows_affected($this->getConnection());
|
||||||
|
return $rows < 0 ? FALSE : $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,10 +22,6 @@ if (!class_exists('dibi', FALSE)) die();
|
|||||||
*/
|
*/
|
||||||
class DibiMySqlDriver extends DibiDriver
|
class DibiMySqlDriver extends DibiDriver
|
||||||
{
|
{
|
||||||
private
|
|
||||||
$insertId = FALSE,
|
|
||||||
$affectedRows = FALSE;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
$formats = array(
|
$formats = array(
|
||||||
'TRUE' => "1",
|
'TRUE' => "1",
|
||||||
@@ -115,37 +111,33 @@ class DibiMySqlDriver extends DibiDriver
|
|||||||
|
|
||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->insertId = $this->affectedRows = FALSE;
|
$res = @mysql_query($sql, $this->getConnection());
|
||||||
$connection = $this->getConnection();
|
|
||||||
$res = @mysql_query($sql, $connection);
|
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) {
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
$this->affectedRows = mysql_affected_rows($connection);
|
} elseif (is_resource($res)) {
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
|
||||||
|
|
||||||
$this->insertId = mysql_insert_id($connection);
|
|
||||||
if ($this->insertId < 1) $this->insertId = FALSE;
|
|
||||||
|
|
||||||
if (is_resource($res)) {
|
|
||||||
return new DibiMySqlResult($res);
|
return new DibiMySqlResult($res);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
} else {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
return $this->affectedRows;
|
$rows = mysql_affected_rows($this->getConnection());
|
||||||
|
return $rows < 0 ? FALSE : $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function insertId()
|
public function insertId()
|
||||||
{
|
{
|
||||||
return $this->insertId;
|
$id = mysql_insert_id($this->getConnection());
|
||||||
|
return $id < 1 ? FALSE : $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,10 +22,6 @@ if (!class_exists('dibi', FALSE)) die();
|
|||||||
*/
|
*/
|
||||||
class DibiMySqliDriver extends DibiDriver
|
class DibiMySqliDriver extends DibiDriver
|
||||||
{
|
{
|
||||||
private
|
|
||||||
$insertId = FALSE,
|
|
||||||
$affectedRows = FALSE;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
$formats = array(
|
$formats = array(
|
||||||
'TRUE' => "1",
|
'TRUE' => "1",
|
||||||
@@ -85,37 +81,33 @@ class DibiMySqliDriver extends DibiDriver
|
|||||||
|
|
||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->insertId = $this->affectedRows = FALSE;
|
$res = @mysqli_query($this->getConnection(), $sql);
|
||||||
$connection = $this->getConnection();
|
|
||||||
$res = @mysqli_query($connection, $sql);
|
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) {
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
$this->affectedRows = mysqli_affected_rows($connection);
|
} elseif (is_object($res)) {
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
|
||||||
|
|
||||||
$this->insertId = mysqli_insert_id($connection);
|
|
||||||
if ($this->insertId < 1) $this->insertId = FALSE;
|
|
||||||
|
|
||||||
if (is_object($res)) {
|
|
||||||
return new DibiMySqliResult($res);
|
return new DibiMySqliResult($res);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
} else {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
return $this->affectedRows;
|
$rows = mysqli_affected_rows($this->getConnection());
|
||||||
|
return $rows < 0 ? FALSE : $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function insertId()
|
public function insertId()
|
||||||
{
|
{
|
||||||
return $this->insertId;
|
$id = mysqli_insert_id($this->getConnection());
|
||||||
|
return $id < 1 ? FALSE : $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -91,20 +91,20 @@ class DibiOdbcDriver extends DibiDriver
|
|||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->affectedRows = FALSE;
|
$this->affectedRows = FALSE;
|
||||||
|
$res = @odbc_exec($this->getConnection(), $sql);
|
||||||
|
|
||||||
$connection = $this->getConnection();
|
if ($res === FALSE) {
|
||||||
$res = @odbc_exec($connection, $sql);
|
return FALSE;
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
} elseif (is_resource($res)) {
|
||||||
|
$this->affectedRows = odbc_num_rows($res);
|
||||||
|
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||||
|
|
||||||
$this->affectedRows = odbc_num_rows($res);
|
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
|
||||||
|
|
||||||
if (is_resource($res)) {
|
|
||||||
return new DibiOdbcResult($res);
|
return new DibiOdbcResult($res);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
} else {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,8 +22,6 @@ if (!class_exists('dibi', FALSE)) die();
|
|||||||
*/
|
*/
|
||||||
class DibiPdoDriver extends DibiDriver
|
class DibiPdoDriver extends DibiDriver
|
||||||
{
|
{
|
||||||
private $affectedRows = FALSE;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
$formats = array(
|
$formats = array(
|
||||||
'TRUE' => "1",
|
'TRUE' => "1",
|
||||||
@@ -65,25 +63,25 @@ class DibiPdoDriver extends DibiDriver
|
|||||||
|
|
||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->affectedRows = FALSE;
|
|
||||||
|
|
||||||
// TODO: or exec() ?
|
// TODO: or exec() ?
|
||||||
$res = $this->getConnection()->query($sql);
|
$res = $this->getConnection()->query($sql);
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) {
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
if ($res instanceof PDOStatement) {
|
} elseif ($res instanceof PDOStatement) {
|
||||||
return new DibiPdoResult($res);
|
return new DibiPdoResult($res);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
} else {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
return $this->affectedRows;
|
// not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ if (!class_exists('dibi', FALSE)) die();
|
|||||||
class DibiPostgreDriver extends DibiDriver
|
class DibiPostgreDriver extends DibiDriver
|
||||||
{
|
{
|
||||||
private
|
private
|
||||||
|
$insertId = FALSE,
|
||||||
$affectedRows = FALSE;
|
$affectedRows = FALSE;
|
||||||
|
|
||||||
public
|
public
|
||||||
@@ -83,7 +84,7 @@ class DibiPostgreDriver extends DibiDriver
|
|||||||
|
|
||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->affectedRows = FALSE;
|
$this->insertId = $this->affectedRows = FALSE;
|
||||||
|
|
||||||
$res = @pg_query($this->getConnection(), $sql);
|
$res = @pg_query($this->getConnection(), $sql);
|
||||||
|
|
||||||
@@ -91,6 +92,9 @@ class DibiPostgreDriver extends DibiDriver
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
} elseif (is_resource($res)) {
|
} elseif (is_resource($res)) {
|
||||||
|
$this->insertId = pg_last_oid($res);
|
||||||
|
if ($this->insertId < 0) $this->insertId = FALSE;
|
||||||
|
|
||||||
$this->affectedRows = pg_affected_rows($res);
|
$this->affectedRows = pg_affected_rows($res);
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||||
|
|
||||||
@@ -112,7 +116,7 @@ class DibiPostgreDriver extends DibiDriver
|
|||||||
|
|
||||||
public function insertId()
|
public function insertId()
|
||||||
{
|
{
|
||||||
return FALSE;
|
return $this->insertId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,10 +22,6 @@ if (!class_exists('dibi', FALSE)) die();
|
|||||||
*/
|
*/
|
||||||
class DibiSqliteDriver extends DibiDriver
|
class DibiSqliteDriver extends DibiDriver
|
||||||
{
|
{
|
||||||
private
|
|
||||||
$insertId = FALSE,
|
|
||||||
$affectedRows = FALSE;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
$formats = array(
|
$formats = array(
|
||||||
'TRUE' => "1",
|
'TRUE' => "1",
|
||||||
@@ -81,38 +77,33 @@ class DibiSqliteDriver extends DibiDriver
|
|||||||
|
|
||||||
public function nativeQuery($sql)
|
public function nativeQuery($sql)
|
||||||
{
|
{
|
||||||
$this->insertId = $this->affectedRows = FALSE;
|
$res = @sqlite_query($this->getConnection(), $sql, SQLITE_ASSOC);
|
||||||
|
|
||||||
$connection = $this->getConnection();
|
if ($res === FALSE) {
|
||||||
$res = @sqlite_query($connection, $sql, SQLITE_ASSOC);
|
return FALSE;
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
} elseif (is_resource($res)) {
|
||||||
|
|
||||||
$this->affectedRows = sqlite_changes($connection);
|
|
||||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
|
||||||
|
|
||||||
$this->insertId = sqlite_last_insert_rowid($connection);
|
|
||||||
if ($this->insertId < 1) $this->insertId = FALSE;
|
|
||||||
|
|
||||||
if (is_resource($res)) {
|
|
||||||
return new DibiSqliteResult($res);
|
return new DibiSqliteResult($res);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
} else {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
return $this->affectedRows;
|
$rows = sqlite_changes($this->getConnection());
|
||||||
|
return $rows < 0 ? FALSE : $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function insertId()
|
public function insertId()
|
||||||
{
|
{
|
||||||
return $this->insertId;
|
$id = sqlite_last_insert_rowid($this->getConnection());
|
||||||
|
return $id < 1 ? FALSE : $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,21 +1,35 @@
|
|||||||
|
<pre>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once '../dibi/dibi.php';
|
require_once '../dibi/dibi.php';
|
||||||
|
|
||||||
|
|
||||||
|
// connects to SQlite
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// connects to SQlite
|
|
||||||
dibi::connect(array(
|
dibi::connect(array(
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'database' => 'sample.sdb',
|
'database' => 'sample.sdb',
|
||||||
));
|
));
|
||||||
|
|
||||||
// connects to MySQL using DSN
|
} catch (DibiException $e) {
|
||||||
|
echo 'DibiException: ', $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// connects to MySQL using DSN
|
||||||
|
try {
|
||||||
dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=utf8');
|
dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=utf8');
|
||||||
|
|
||||||
|
} catch (DibiException $e) {
|
||||||
|
echo 'DibiException: ', $e;
|
||||||
|
}
|
||||||
|
|
||||||
// connects to MySQL / MySQLi
|
|
||||||
|
|
||||||
|
|
||||||
|
// connects to MySQL / MySQLi
|
||||||
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect(array(
|
||||||
'driver' => 'mysql', // or 'mysqli'
|
'driver' => 'mysql', // or 'mysqli'
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
@@ -25,8 +39,15 @@ try {
|
|||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
} catch (DibiException $e) {
|
||||||
|
echo 'DibiException: ', $e;
|
||||||
|
}
|
||||||
|
|
||||||
// connects to ODBC
|
|
||||||
|
|
||||||
|
|
||||||
|
// connects to ODBC
|
||||||
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect(array(
|
||||||
'driver' => 'odbc',
|
'driver' => 'odbc',
|
||||||
'username' => 'root',
|
'username' => 'root',
|
||||||
@@ -34,22 +55,43 @@ try {
|
|||||||
'database' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\\Database.mdb',
|
'database' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\\Database.mdb',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
} catch (DibiException $e) {
|
||||||
|
echo 'DibiException: ', $e;
|
||||||
|
}
|
||||||
|
|
||||||
// connects to PostgreSql
|
|
||||||
|
|
||||||
|
|
||||||
|
// connects to PostgreSql
|
||||||
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect(array(
|
||||||
'driver' => 'postgre',
|
'driver' => 'postgre',
|
||||||
'string' => 'host=localhost port=5432 dbname=mary',
|
'string' => 'host=localhost port=5432 dbname=mary',
|
||||||
'persistent' => TRUE,
|
'persistent' => TRUE,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
} catch (DibiException $e) {
|
||||||
|
echo 'DibiException: ', $e;
|
||||||
|
}
|
||||||
|
|
||||||
// connects to PDO
|
|
||||||
|
|
||||||
|
|
||||||
|
// connects to PDO
|
||||||
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect(array(
|
||||||
'driver' => 'pdo',
|
'driver' => 'pdo',
|
||||||
'dsn' => 'sqlite2::memory:',
|
'dsn' => 'sqlite2::memory:',
|
||||||
));
|
));
|
||||||
|
|
||||||
// connects to MS SQL
|
} catch (DibiException $e) {
|
||||||
|
echo 'DibiException: ', $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// connects to MS SQL
|
||||||
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect(array(
|
||||||
'driver' => 'mssql',
|
'driver' => 'mssql',
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
@@ -58,7 +100,5 @@ try {
|
|||||||
));
|
));
|
||||||
|
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
|
echo 'DibiException: ', $e;
|
||||||
echo "DibiException: <pre>", $e;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user