mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
* added dibi::date & dibi::datetime
* DibiConnection::insertId && affectedRows throws exception on failure * added protected throwException() to drivers * DibiPostgreDriver - can build connection string * DibiSqliteDriver - support for parameters 'format:date' & 'format:datetime' * fixed query errors in DibiSqliteDriver * DibiConnection prevents serialization and multiple transactions
This commit is contained in:
@@ -14,7 +14,7 @@ try {
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
@@ -28,7 +28,7 @@ try {
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
@@ -49,7 +49,7 @@ try {
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
@@ -68,7 +68,7 @@ try {
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
@@ -86,7 +86,7 @@ try {
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
@@ -103,7 +103,7 @@ try {
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
@@ -121,7 +121,7 @@ try {
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
@@ -139,6 +139,6 @@ try {
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage();
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
@@ -1,73 +0,0 @@
|
||||
<h1>DibiVariableInterface example</h1>
|
||||
<?php
|
||||
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
|
||||
// required since PHP 5.1.0
|
||||
if (function_exists('date_default_timezone_set')) {
|
||||
date_default_timezone_set('Europe/Prague');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pseudotype for UNIX timestamp representation
|
||||
*/
|
||||
class MyDateTime implements DibiVariableInterface
|
||||
{
|
||||
/**
|
||||
* Unix timestamp
|
||||
* @var int
|
||||
*/
|
||||
protected $time;
|
||||
|
||||
|
||||
|
||||
public function __construct($time = NULL)
|
||||
{
|
||||
if ($time === NULL)
|
||||
$this->time = time(); // current time
|
||||
|
||||
elseif (is_string($time))
|
||||
$this->time = strtotime($time); // try convert to timestamp
|
||||
|
||||
else
|
||||
$this->time = (int) $time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Format for SQL
|
||||
*
|
||||
* @param object destination DibiDriver
|
||||
* @param string optional modifier
|
||||
* @return string
|
||||
*/
|
||||
public function toSql(DibiDriverInterface $driver, $modifier)
|
||||
{
|
||||
return $driver->format($this->time, dibi::FIELD_DATETIME); // format according to driver's spec.
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// CHANGE TO REAL PARAMETERS!
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite',
|
||||
'database' => 'sample.sdb',
|
||||
));
|
||||
|
||||
|
||||
|
||||
// generate and dump SQL
|
||||
dibi::test("
|
||||
INSERT INTO [mytable]", array(
|
||||
'A' => 12,
|
||||
'B' => NULL,
|
||||
'C' => new MyDateTime(31542), // using out class
|
||||
'D' => 'any string',
|
||||
));
|
30
examples/datetime.demo.php
Normal file
30
examples/datetime.demo.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<h1>DibiVariableInterface example</h1>
|
||||
<?php
|
||||
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
|
||||
// required since PHP 5.1.0
|
||||
if (function_exists('date_default_timezone_set')) {
|
||||
date_default_timezone_set('Europe/Prague');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// CHANGE TO REAL PARAMETERS!
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite',
|
||||
'database' => 'sample.sdb',
|
||||
'format:date' => "'Y-m-d'",
|
||||
'format:datetime' => "'Y-m-d H-i-s'",
|
||||
));
|
||||
|
||||
|
||||
|
||||
// generate and dump SQL
|
||||
dibi::test("
|
||||
INSERT INTO [mytable]", array(
|
||||
'id' => 123,
|
||||
'date' => dibi::date('12.3.2007'),
|
||||
'stamp' => dibi::dateTime('23.1.2007 10:23'),
|
||||
));
|
28
examples/transaction.php
Normal file
28
examples/transaction.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<h1>dibi transaction example</h1>
|
||||
<pre>
|
||||
<?php
|
||||
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite',
|
||||
'database' => 'sample.sdb',
|
||||
));
|
||||
|
||||
|
||||
echo "<h2>Before:</h2>\n";
|
||||
dibi::query('SELECT * FROM [products]')->dump();
|
||||
|
||||
|
||||
|
||||
dibi::begin();
|
||||
dibi::query('INSERT INTO [products]', array(
|
||||
'title' => 'Test product',
|
||||
));
|
||||
dibi::rollback(); // or dibi::commit();
|
||||
|
||||
|
||||
|
||||
echo "<h2>After:</h2>\n";
|
||||
dibi::query('SELECT * FROM [products]')->dump();
|
Reference in New Issue
Block a user