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