|
8 | 8 |
|
9 | 9 | This is a small easy-to-use PHP component for working with a database by PDO. It provides some public methods to compose SQL queries and manipulate data. Each SQL query is prepared and safe. PDO (see `Connection` class) fetches data to _arrays_ by default. At present time the component supports MySQL and SQLite (file or memory). |
10 | 10 |
|
11 | | -**PAY ATTENTION! v0.2 and v0.3+ are incompatible.** |
| 11 | +**PAY ATTENTION! v0.2 and v0.3+ are incompatible.** |
12 | 12 |
|
13 | 13 | ## Contributing |
14 | 14 |
|
@@ -48,7 +48,7 @@ to the `require section` of your `composer.json` file. |
48 | 48 | - `column()` executes SQL query and return the first column of result (`fetchColumn()`) |
49 | 49 | - `pluck($key_index, $col_index)` executes SQL query and returns an array (the key (usually ID) and the needed column of result), `key_index` is `0` and `col_index` is `1` by default |
50 | 50 | - `go()` this method is for non `SELECT` queries. it executes SQL query and return nothing (but returns the last inserted row ID for `INSERT` method) |
51 | | -- `count()` prepares a query with SQL `COUNT()` function |
| 51 | +- `count()` prepares a query with SQL `COUNT(*)` function and executes it |
52 | 52 | - `exists()` returns `true` if SQL query result has a row |
53 | 53 | - `query($sql, $params[], $fetch_type)` executes prepared `$sql` with `$params`. it can be used for custom queries |
54 | 54 | - 'SQL' methods are presented in [Usage section](#usage-examples) |
@@ -119,6 +119,25 @@ $results = $query->select('users')->where([['name', 'NOT LIKE', '%John%']])->all |
119 | 119 | ```sql |
120 | 120 | SELECT * FROM `users` WHERE (`name` NOT LIKE '%John%'); |
121 | 121 | ``` |
| 122 | +- Select a row with a `IS NULL` and `IS NOT NULL` condition (since 0.3.5) |
| 123 | +```php |
| 124 | +$results = $query->select('users')->isNull('phone')->all(); |
| 125 | +# or |
| 126 | +$results = $query->select('users')->where([['phone', 'is null']])->all(); |
| 127 | +``` |
| 128 | +```sql |
| 129 | +SELECT * FROM `users` WHERE (`phone` IS NULL); |
| 130 | +``` |
| 131 | +```php |
| 132 | +$results = $query->select('customers')->isNotNull('address')->all(); |
| 133 | +# or |
| 134 | +$results = $query->select('customers')->notNull('address')->all(); |
| 135 | +# or |
| 136 | +$results = $query->select('customers')->where([['address', 'is not null']])->all(); |
| 137 | +``` |
| 138 | +```sql |
| 139 | +SELECT * FROM `customers` WHERE (`address` IS NOT NULL); |
| 140 | +``` |
122 | 141 | - Select rows with `OFFSET` and `LIMIT` |
123 | 142 | ```php |
124 | 143 | $results = $query->select('posts') |
@@ -352,13 +371,17 @@ $query->delete('comments') |
352 | 371 | DELETE FROM `comments` WHERE `user_id` = 10; |
353 | 372 | ``` |
354 | 373 | - Truncate a table |
| 374 | + |
| 375 | +This method will be moved to another class |
355 | 376 | ```php |
356 | 377 | $query->truncate('users')->go(); |
357 | 378 | ``` |
358 | 379 | ```sql |
359 | 380 | TRUNCATE TABLE `users`; |
360 | 381 | ``` |
361 | 382 | - Drop a table |
| 383 | + |
| 384 | +This method will be moved to another class |
362 | 385 | ```php |
363 | 386 | $query->drop('temporary')->go(); |
364 | 387 | ``` |
|
0 commit comments