1
0
mirror of https://github.com/dg/dibi.git synced 2025-09-16 00:52:29 +02:00

Compare commits

..

14 Commits

Author SHA1 Message Date
David Grudl
cec699af0f Released version 3.2.1 2018-04-14 20:49:54 +02:00
David Grudl
59a4cc2fe0 Revert "loader: uses only Composer's autoloader"
This reverts commit 5c806ea517.
2018-04-14 20:49:14 +02:00
David Grudl
985f09417e Translator: improved Expression usage 2018-04-14 20:49:14 +02:00
David Grudl
729d133d70 PdoDriver: improved detection of query result [Closes #279] 2018-03-28 18:04:35 +02:00
David Grudl
759c63bca0 appveyor: improved 2018-03-23 17:53:22 +01:00
David Grudl
f9fc7e330d examples: added notice when vendor/autoload.php not found 2018-03-23 11:57:59 +01:00
jahudka
dbca915bfe Firebird: fix datetime precision (#277) (#273) 2018-03-18 10:49:20 +01:00
Miloslav Hůla
1bae6eae08 tests: connection removed from bootstrap 2018-03-09 15:09:48 +01:00
David Grudl
34b7e22d40 readme.md: static -> object 2018-03-09 15:09:48 +01:00
David Grudl
369f5ee7d6 readme: updated installation and requirements 2018-03-09 15:09:48 +01:00
David Grudl
2d74bb3da0 examples: uses composer autoload 2018-03-09 14:50:36 +01:00
David Grudl
a5422a65c9 loader: old class names triggers E_USER_DEPRECATED, removed preloading (BC break) 2018-03-09 14:44:06 +01:00
David Grudl
5c806ea517 loader: uses only Composer's autoloader
# Conflicts:
#	src/loader.php
2018-03-09 14:38:18 +01:00
David Grudl
ecafed6246 opened 3.2-dev 2018-03-09 14:37:31 +01:00
23 changed files with 98 additions and 79 deletions

View File

@@ -56,4 +56,4 @@ test_script:
on_failure:
# Print *.actual content
- type tests\dibi\output\*.actual
- for /r %%x in (*.actual) do ( type "%%x" )

View File

@@ -26,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.1-dev"
"dev-master": "3.2-dev"
}
}
}

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
// connects to SQlite using dibi class

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
dibi::connect([

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
dibi::connect([

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
dibi::connect([

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
dibi::connect([

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
date_default_timezone_set('Europe/Prague');

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
date_default_timezone_set('Europe/Prague');

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
date_default_timezone_set('Europe/Prague');

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
dibi::connect([

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
date_default_timezone_set('Europe/Prague');

View File

@@ -6,7 +6,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
dibi::connect([

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
dibi::connect([

View File

@@ -4,7 +4,9 @@
<?php
require __DIR__ . '/../src/loader.php';
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer install`');
}
dibi::connect([

View File

@@ -7,22 +7,28 @@
[![Latest Stable Version](https://poser.pugx.org/dibi/dibi/v/stable)](https://github.com/dg/dibi/releases)
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/dg/dibi/blob/master/license.md)
Introduction
------------
Database access functions in PHP are not standardised. This library
hides the differences between them, and above all, it gives you a very handy interface.
The best way to install Dibi is to use a [Composer](https://getcomposer.org/download):
php composer.phar require dibi/dibi
Installation
------------
Or you can download the latest package from https://dibiphp.com. In this
package is also `Dibi.minified`, shrinked single-file version of whole Dibi,
useful when you don't want to modify the library, but just use it.
The recommended way to install Dibi is via Composer (alternatively you can [download package](https://github.com/dg/dibi/releases)):
Dibi requires PHP 5.4.4 or later. It has been tested with PHP 7 too.
```bash
composer require dibi/dibi
```
The Dibi 3.x requires PHP version 5.4.4 and supports PHP up to 7.2.
Examples
--------
Usage
-----
Refer to the `examples` directory for examples. Dibi documentation is
available on the [homepage](https://dibiphp.com).
@@ -30,34 +36,34 @@ available on the [homepage](https://dibiphp.com).
Connect to database:
```php
// connect to database (static way)
dibi::connect([
'driver' => 'mysql',
$dibi = new Dibi\Connection([
'driver' => 'mysqli',
'host' => 'localhost',
'username' => 'root',
'password' => '***',
]);
// or object way; in all other examples use $connection-> instead of dibi::
$connection = new DibiConnection($options);
// or static way; in all other examples use dibi:: instead of $dibi->
dibi::connect($options);
```
SELECT, INSERT, UPDATE
```php
dibi::query('SELECT * FROM users WHERE id = ?', $id);
$dibi->query('SELECT * FROM users WHERE id = ?', $id);
$arr = [
'name' => 'John',
'is_admin' => true,
];
dibi::query('INSERT INTO users', $arr);
$dibi->query('INSERT INTO users', $arr);
// INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1)
dibi::query('UPDATE users SET', $arr, 'WHERE `id`=?', $x);
$dibi->query('UPDATE users SET', $arr, 'WHERE `id`=?', $x);
// UPDATE users SET `name`='John', `is_admin`=1 WHERE `id` = 123
dibi::query('UPDATE users SET', [
$dibi->query('UPDATE users SET', [
'title' => array('SHA1(?)', 'tajneheslo'),
]);
// UPDATE users SET 'title' = SHA1('tajneheslo')
@@ -66,7 +72,7 @@ dibi::query('UPDATE users SET', [
Getting results
```php
$result = dibi::query('SELECT * FROM users');
$result = $dibi->query('SELECT * FROM users');
$value = $result->fetchSingle(); // single value
$all = $result->fetchAll(); // all rows
@@ -82,7 +88,7 @@ foreach ($result as $n => $row) {
Modifiers for arrays:
```php
dibi::query('SELECT * FROM users WHERE %and', [
$dibi->query('SELECT * FROM users WHERE %and', [
array('number > ?', 10),
array('number < ?', 100),
]);
@@ -105,7 +111,7 @@ dibi::query('SELECT * FROM users WHERE %and', [
Modifiers for LIKE
```php
dibi::query("SELECT * FROM table WHERE name LIKE %like~", $query);
$dibi->query("SELECT * FROM table WHERE name LIKE %like~", $query);
```
<table>
@@ -117,7 +123,7 @@ dibi::query("SELECT * FROM table WHERE name LIKE %like~", $query);
DateTime:
```php
dibi::query('UPDATE users SET', [
$dibi->query('UPDATE users SET', [
'time' => new DateTime,
]);
// UPDATE users SET ('2008-01-01 01:08:10')

View File

@@ -313,7 +313,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("'Y-m-d H:i:s.u'");
return "'" . substr($value->format('Y-m-d H:i:s.u'), 0, -2) . "'";
}

View File

@@ -104,23 +104,14 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
*/
public function query($sql)
{
// must detect if SQL returns result set or num of affected rows
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1];
$this->affectedRows = false;
if (isset($list[$cmd])) {
$this->affectedRows = $this->connection->exec($sql);
if ($this->affectedRows !== false) {
return null;
}
} else {
$res = $this->connection->query($sql);
if ($res) {
return $this->createResultDriver($res);
}
$res = $this->connection->query($sql);
if ($res) {
$this->affectedRows = $res->rowCount();
return $res->columnCount() ? $this->createResultDriver($res) : null;
}
$this->affectedRows = false;
list($sqlState, $code, $message) = $this->connection->errorInfo();
$message = "SQLSTATE[$sqlState]: $message";
switch ($this->driverName) {

View File

@@ -315,7 +315,11 @@ final class Translator
if ($modifier) {
if ($value !== null && !is_scalar($value)) { // array is already processed
if ($value instanceof Literal && ($modifier === 'sql' || $modifier === 'SQL')) {
$modifier = 'SQL';
return (string) $value;
} elseif ($value instanceof Expression && $modifier === 'ex') {
return call_user_func_array([$this->connection, 'translate'], $value->getValues());
} elseif (($value instanceof \DateTime || $value instanceof \DateTimeInterface) && ($modifier === 'd' || $modifier === 't' || $modifier === 'dt')) {
// continue
} else {

View File

@@ -22,8 +22,8 @@ class dibi
/** version */
const
VERSION = '3.1.1',
REVISION = 'released on 2018-03-09';
VERSION = '3.2.1',
REVISION = 'released on 2018-04-14';
/** sorting order */
const
@@ -64,7 +64,7 @@ class dibi
/** @var string Default dibi driver */
public static $defaultDriver = 'mysqli';
/** @var Dibi\Connection[] Connection registry storage for DibiConnection objects */
/** @var Dibi\Connection[] Connection registry storage for Dibi\Connection objects */
private static $registry = [];
/** @var Dibi\Connection Current connection */

View File

@@ -114,26 +114,9 @@ spl_autoload_register(function ($class) {
if (isset($map[$class])) {
require __DIR__ . '/Dibi/' . $map[$class];
} elseif (isset($old2new[$class])) {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$location = isset($trace[1]['file']) ? 'used in ' . $trace[1]['file'] . ':' . $trace[1]['line'] : '';
trigger_error("Class $class $location has been renamed to {$old2new[$class]}.", E_USER_DEPRECATED);
class_alias($old2new[$class], $class);
}
});
// preload for compatiblity
array_map('class_exists', [
'DibiConnection',
'DibiDateTime',
'DibiDriverException',
'DibiEvent',
'DibiException',
'DibiFluent',
'DibiLiteral',
'DibiNotImplementedException',
'DibiNotSupportedException',
'DibiPcreException',
'DibiProcedureException',
'DibiResult',
'DibiRow',
'IDataSource',
'IDibiDriver',
]);

View File

@@ -505,6 +505,18 @@ Assert::same(
);
Assert::same(
reformat('SELECT * FROM [table] WHERE (([left] = 1) OR ([top] = 2)) AND (number < 100)'),
$conn->translate('SELECT * FROM `table` WHERE %and', [
new Dibi\Expression('%or', [
'left' => 1,
'top' => 2,
]),
new Dibi\Expression('number < %i', 100),
])
);
$e = Assert::exception(function () use ($conn) {
$array6 = [
'id' => [1, 2, 3, 4],

View File

@@ -40,9 +40,6 @@ if ($config['driver'] === 'mysql' && PHP_VERSION_ID >= 70000) {
}
$conn = new Dibi\Connection($config);
function test(Closure $function)
{
$function();