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

Compare commits

...

7 Commits
v3.1 ... v3.2.0

Author SHA1 Message Date
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
18 changed files with 48 additions and 115 deletions

View File

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

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
// connects to SQlite using dibi class

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
dibi::connect([

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
dibi::connect([

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
dibi::connect([

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
dibi::connect([

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set('Europe/Prague');

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set('Europe/Prague');

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set('Europe/Prague');

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
dibi::connect([

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set('Europe/Prague');

View File

@@ -6,7 +6,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
dibi::connect([

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
dibi::connect([

View File

@@ -4,7 +4,7 @@
<?php
require __DIR__ . '/../src/loader.php';
require __DIR__ . '/../vendor/autoload.php';
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

@@ -22,7 +22,7 @@ class dibi
/** version */
const
VERSION = '3.1.1',
VERSION = '3.2.0',
REVISION = 'released on 2018-03-09';
/** sorting order */
@@ -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

@@ -12,58 +12,7 @@ if (PHP_VERSION_ID < 50404) {
spl_autoload_register(function ($class) {
static $map = [
'dibi' => 'dibi.php',
'Dibi\Bridges\Nette\DibiExtension22' => 'Bridges/Nette/DibiExtension22.php',
'Dibi\Bridges\Tracy\Panel' => 'Bridges/Tracy/Panel.php',
'Dibi\Connection' => 'Connection.php',
'Dibi\DataSource' => 'DataSource.php',
'Dibi\DateTime' => 'DateTime.php',
'Dibi\Driver' => 'interfaces.php',
'Dibi\DriverException' => 'exceptions.php',
'Dibi\Drivers\FirebirdDriver' => 'Drivers/FirebirdDriver.php',
'Dibi\Drivers\SqlsrvDriver' => 'Drivers/SqlsrvDriver.php',
'Dibi\Drivers\SqlsrvReflector' => 'Drivers/SqlsrvReflector.php',
'Dibi\Drivers\MsSqlDriver' => 'Drivers/MsSqlDriver.php',
'Dibi\Drivers\MsSqlReflector' => 'Drivers/MsSqlReflector.php',
'Dibi\Drivers\MySqlDriver' => 'Drivers/MySqlDriver.php',
'Dibi\Drivers\MySqliDriver' => 'Drivers/MySqliDriver.php',
'Dibi\Drivers\MySqlReflector' => 'Drivers/MySqlReflector.php',
'Dibi\Drivers\OdbcDriver' => 'Drivers/OdbcDriver.php',
'Dibi\Drivers\OracleDriver' => 'Drivers/OracleDriver.php',
'Dibi\Drivers\PdoDriver' => 'Drivers/PdoDriver.php',
'Dibi\Drivers\PostgreDriver' => 'Drivers/PostgreDriver.php',
'Dibi\Drivers\Sqlite3Driver' => 'Drivers/Sqlite3Driver.php',
'Dibi\Drivers\SqliteReflector' => 'Drivers/SqliteReflector.php',
'Dibi\Event' => 'Event.php',
'Dibi\Exception' => 'exceptions.php',
'Dibi\Fluent' => 'Fluent.php',
'Dibi\HashMap' => 'HashMap.php',
'Dibi\HashMapBase' => 'HashMap.php',
'Dibi\Helpers' => 'Helpers.php',
'Dibi\IDataSource' => 'interfaces.php',
'Dibi\Literal' => 'Literal.php',
'Dibi\Loggers\FileLogger' => 'Loggers/FileLogger.php',
'Dibi\Loggers\FirePhpLogger' => 'Loggers/FirePhpLogger.php',
'Dibi\NotImplementedException' => 'exceptions.php',
'Dibi\NotSupportedException' => 'exceptions.php',
'Dibi\PcreException' => 'exceptions.php',
'Dibi\ProcedureException' => 'exceptions.php',
'Dibi\Reflection\Column' => 'Reflection/Column.php',
'Dibi\Reflection\Database' => 'Reflection/Database.php',
'Dibi\Reflection\ForeignKey' => 'Reflection/ForeignKey.php',
'Dibi\Reflection\Index' => 'Reflection/Index.php',
'Dibi\Reflection\Result' => 'Reflection/Result.php',
'Dibi\Reflection\Table' => 'Reflection/Table.php',
'Dibi\Reflector' => 'interfaces.php',
'Dibi\Result' => 'Result.php',
'Dibi\ResultDriver' => 'interfaces.php',
'Dibi\ResultIterator' => 'ResultIterator.php',
'Dibi\Row' => 'Row.php',
'Dibi\Strict' => 'Strict.php',
'Dibi\Translator' => 'Translator.php',
'Dibi\Type' => 'Type.php',
], $old2new = [
$old2new = [
'DibiColumnInfo' => 'Dibi\Reflection\Column',
'DibiConnection' => 'Dibi\Connection',
'DibiDatabaseInfo' => 'Dibi\Reflection\Database',
@@ -111,29 +60,10 @@ spl_autoload_register(function ($class) {
'Dibi\Drivers\MsSql2005Driver' => 'Dibi\Drivers\SqlsrvDriver',
'Dibi\Drivers\MsSql2005Reflector' => 'Dibi\Drivers\SqlsrvReflector',
];
if (isset($map[$class])) {
require __DIR__ . '/Dibi/' . $map[$class];
} elseif (isset($old2new[$class])) {
if (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

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