1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-07 14:46:50 +02:00
This commit is contained in:
David Grudl
2020-10-07 03:18:17 +02:00
parent 6e41c4223b
commit f444b5d993

View File

@@ -48,11 +48,11 @@ The database connection is represented by the object `Dibi\Connection`:
```php ```php
$database = new Dibi\Connection([ $database = new Dibi\Connection([
'driver' => 'mysqli', 'driver' => 'mysqli',
'host' => 'localhost', 'host' => 'localhost',
'username' => 'root', 'username' => 'root',
'password' => '***', 'password' => '***',
'database' => 'table', 'database' => 'table',
]); ]);
$result = $database->query('SELECT * FROM users'); $result = $database->query('SELECT * FROM users');
@@ -62,12 +62,12 @@ Alternatively, you can use the `dibi` static register, which maintains a connect
```php ```php
dibi::connect([ dibi::connect([
'driver' => 'mysqli', 'driver' => 'mysqli',
'host' => 'localhost', 'host' => 'localhost',
'username' => 'root', 'username' => 'root',
'password' => '***', 'password' => '***',
'database' => 'test', 'database' => 'test',
'charset' => 'utf8', 'charset' => 'utf8',
]); ]);
$result = dibi::query('SELECT * FROM users'); $result = dibi::query('SELECT * FROM users');
@@ -235,8 +235,8 @@ Example:
```php ```php
$arr = [ $arr = [
'a' => 'hello', 'a' => 'hello',
'b' => true, 'b' => true,
]; ];
$database->query('INSERT INTO table %v', $arr); $database->query('INSERT INTO table %v', $arr);
@@ -508,7 +508,7 @@ $all = $result->fetchAssoc('customer_id|order_id');
// we will iterate like this: // we will iterate like this:
foreach ($all as $customerId => $orders) { foreach ($all as $customerId => $orders) {
foreach ($orders as $orderId => $order) { foreach ($orders as $orderId => $order) {
... ...
} }
} }
``` ```
@@ -540,7 +540,7 @@ $all = $result->fetchAssoc('name[]order_id');
// we get all the Arnolds in the results // we get all the Arnolds in the results
foreach ($all['Arnold Rimmer'] as $arnoldOrders) { foreach ($all['Arnold Rimmer'] as $arnoldOrders) {
foreach ($arnoldOrders as $orderId => $order) { foreach ($arnoldOrders as $orderId => $order) {
... ...
} }
} }
``` ```
@@ -554,8 +554,8 @@ foreach ($all as $customerId => $orders) {
echo "Customer $customerId": echo "Customer $customerId":
foreach ($orders as $orderId => $order) { foreach ($orders as $orderId => $order) {
echo "ID number: $order->number"; echo "ID number: $order->number";
// customer name is in $order->name // customer name is in $order->name
} }
} }
``` ```
@@ -577,7 +577,7 @@ foreach ($all as $customerId => $row) {
echo "Customer $row->name": echo "Customer $row->name":
foreach ($row->order_id as $orderId => $order) { foreach ($row->order_id as $orderId => $order) {
echo "ID number: $order->number"; echo "ID number: $order->number";
} }
} }
``` ```