1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-01 11:50:15 +02:00

used PHP 5.4 syntax

This commit is contained in:
David Grudl
2015-10-06 01:39:01 +02:00
parent a32e24262f
commit 7c1f735f9b
69 changed files with 718 additions and 733 deletions

View File

@@ -30,12 +30,12 @@ Connect to database:
```php
// connect to database (static way)
dibi::connect(array(
dibi::connect([
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'root',
'password' => '***',
));
]);
// or object way; in all other examples use $connection-> instead of dibi::
$connection = new DibiConnection($options);
@@ -46,19 +46,19 @@ SELECT, INSERT, UPDATE
```php
dibi::query('SELECT * FROM users WHERE id = ?', $id);
$arr = array(
$arr = [
'name' => 'John',
'is_admin' => TRUE,
);
];
dibi::query('INSERT INTO users', $arr);
// INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1)
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', array(
dibi::query('UPDATE users SET', [
'title' => array('SHA1(?)', 'tajneheslo'),
));
]);
// UPDATE users SET 'title' = SHA1('tajneheslo')
```
@@ -81,10 +81,10 @@ foreach ($result as $n => $row) {
Modifiers for arrays:
```php
dibi::query('SELECT * FROM users WHERE %and', array(
dibi::query('SELECT * FROM users WHERE %and', [
array('number > ?', 10),
array('number < ?', 100),
));
]);
// SELECT * FROM users WHERE (number > 10) AND (number < 100)
```
@@ -116,9 +116,9 @@ dibi::query("SELECT * FROM table WHERE name LIKE %like~", $query);
DateTime:
```php
dibi::query('UPDATE users SET', array(
dibi::query('UPDATE users SET', [
'time' => new DateTime,
));
]);
// UPDATE users SET ('2008-01-01 01:08:10')
```