-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better queryBuilder, quoteIdentifier, updated docs. For 1.0.2 release
- Loading branch information
Showing
27 changed files
with
796 additions
and
611 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
# Result | ||
|
||
Every query executed will return `Blrf\Dbal\Result` object. | ||
|
||
```php | ||
<?php | ||
class Result { | ||
public readonly array $rows = []; | ||
public readonly ?int $insertId = null; | ||
public readonly int $affectedRows = 0; | ||
public readonly int $warningCount = 0; | ||
} | ||
``` | ||
|
||
## $rows | ||
|
||
`SELECT` queries will return result with `$rows` array. | ||
|
||
### Iterator | ||
|
||
Result implements [Iterator](https://www.php.net/iterator) so you can also use Result object as an array: | ||
|
||
```php | ||
<?php | ||
foreach ($result as $row) { | ||
echo " - my awesome row: " . print_r($row, true) . "\n"; | ||
} | ||
``` | ||
|
||
## $insertId | ||
|
||
`INSERT` queries with sequence/autoincrement/... table keys will return last insert id. | ||
|
||
## $affectedRows | ||
|
||
`UPDATE` or `DELETE` queries will report affected rows. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
$config = new Blrf\Dbal\Config('mysql://user:pass@localhost/bookstore'); | ||
|
||
$config->create()->then( | ||
function (Blrf\Dbal\Connection $db) { | ||
// start query builder | ||
$qb = $db->query() | ||
->update('book') | ||
->values(['title' => 'Moby Dick: ' . time()]); // automatically added to parameters | ||
$qb->where($qb->condition('book_id')) | ||
->addParameter([11089]) // we add parameter | ||
->limit(1); | ||
echo "sql: " . $qb->getSql() . "\n"; | ||
// sql: UPDATE book SET title = ? WHERE book_id = ? LIMIT 1 | ||
return $qb->execute(); | ||
} | ||
)->then( | ||
function (Blrf\Dbal\Result $result) { | ||
print_r($result); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
$config = new Blrf\Dbal\Config('mysql://user:pass@localhost/bookstore'); | ||
|
||
$config->create()->then( | ||
function (Blrf\Dbal\Connection $db) { | ||
// start query builder | ||
$qb = $db->query() | ||
->update('address') | ||
->join( | ||
'customer_address', | ||
'customer_address.address_id = address.address_id' | ||
) | ||
->join( | ||
'address_status', | ||
'address_status.status_id = customer_address.status_id' | ||
) | ||
->values(['address.street_name' => 'Inactive: ' . time()]) // parameter is added | ||
->where( | ||
fn($cb) => $cb->and( | ||
$cb->eq('address_status.address_status'), | ||
$cb->eq('customer_address.customer_id') | ||
) | ||
) | ||
->addParameter('Inactive', 3); | ||
echo "sql: " . $qb->getSql() . "\n"; | ||
// sql: UPDATE address INNER JOIN customer_address ON customer_address.address_id = address.address_id | ||
// INNER JOIN address_status ON address_status.status_id = customer_address.status_id | ||
// SET address.street_name = ? | ||
// WHERE (address_status.address_status = ? AND customer_address.customer_id = ?) | ||
return $qb->execute(); | ||
} | ||
)->then( | ||
function (Blrf\Dbal\Result $result) { | ||
print_r($result); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.