Skip to content

Commit 2666fc1

Browse files
authored
Readme and docs updates (#6)
1 parent 7291a4c commit 2666fc1

16 files changed

+110
-103
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
### Changelog
22

3+
##### v2.1.1
4+
+ Updated `README` and docs contents
5+
- Cleaned up the php examples and content
6+
37
##### v2.1.0
48
+ Updated internal tools php-cs-fixer and phpstan
59
- Cleared all phpstan errors up to level 8 (max)

README.md

+32-21
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Latest Stable Version](https://poser.pugx.org/ParticleBits/pdo/v/stable)](https://packagist.org/packages/ParticleBits/pdo)
55
[![License](https://poser.pugx.org/ParticleBits/pdo/license)](https://packagist.org/packages/ParticleBits/pdo)
66

7-
Smallest possible PDO database while being super useful
7+
Smallest possible PDO database while still being super useful
88

99
### Installation
1010

@@ -16,11 +16,16 @@ Use [Composer](https://getcomposer.org/)
1616
}
1717
```
1818

19-
Compatible with PHP 5.6 and higher. Tested on all versions of PHP 5.6 and higher.
19+
### Features
20+
21+
* Compatible with PHP 5.6 and higher!
22+
* Tested on all versions of PHP 5.6 -> 7.4 _(Not tested yet on PHP 8.x)_
23+
* No dependencies other than the PDO extension
24+
* Tiny footprint
2025

2126
### Usage
2227

23-
Examples selecting, inserting, updating and deleting data from or into `users` table.
28+
Examples selecting, inserting, updating and deleting data from or into the `users` table.
2429

2530
```php
2631
require_once 'vendor/autoload.php';
@@ -32,36 +37,42 @@ $pwd = 'your_db_password';
3237
$pdo = new \Pb\PDO\Database($dsn, $usr, $pwd);
3338

3439
// SELECT * FROM users WHERE id = ?
35-
$selectStatement = $pdo->select()
36-
->from('users')
37-
->where('id', '=', 1234);
40+
$stmt = $pdo
41+
->select()
42+
->from('users')
43+
->where('id', '=', 1234)
44+
->execute();
3845

39-
$stmt = $selectStatement->execute();
4046
$data = $stmt->fetch();
4147

42-
// INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? )
43-
$insertStatement = $pdo->insert(['id', 'usr', 'pwd'])
44-
->into('users')
45-
->values([1234, 'your_username', 'your_password']);
48+
// INSERT INTO users (id , usr , pwd) VALUES (? , ? , ?)
49+
$stmt = $pdo
50+
->insert(['id', 'usr', 'pwd'])
51+
->into('users')
52+
->values([1234, 'your_username', 'your_password']);
4653

47-
$insertId = $insertStatement->execute(false);
54+
$insertId = $stmt->execute(true); // true returns insert ID
4855

4956
// UPDATE users SET pwd = ? WHERE id = ?
50-
$updateStatement = $pdo->update(['pwd' => 'your_new_password'])
51-
->table('users')
52-
->where('id', '=', 1234);
57+
$stmt = $pdo
58+
->update(['pwd' => 'your_new_password'])
59+
->table('users')
60+
->where('id', '=', 1234);
5361

54-
$affectedRows = $updateStatement->execute();
62+
$affectedRows = $stmt->execute();
5563

5664
// DELETE FROM users WHERE id = ?
57-
$deleteStatement = $pdo->delete()
58-
->from('users')
59-
->where('id', '=', 1234);
65+
$stmt = $pdo
66+
->delete()
67+
->from('users')
68+
->where('id', '=', 1234);
6069

61-
$affectedRows = $deleteStatement->execute();
70+
$affectedRows = $stmt->execute();
6271
```
6372

64-
> The `sqlsrv` extension will fail to connect when using error mode `PDO::ERRMODE_EXCEPTION` (default). To connect, you will need to explicitly pass `array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING)` (or `PDO::ERRMODE_SILENT`) into the constructor, or override the `getDefaultOptions()` method when using `sqlsrv`.
73+
### Notes on the `sqlsrv` extension
74+
75+
The `sqlsrv` extension will fail to connect when using error mode `PDO::ERRMODE_EXCEPTION` (default). To connect, you will need to explicitly pass `array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING)` (or `PDO::ERRMODE_SILENT`) into the constructor, or override the `getDefaultOptions()` method when using `sqlsrv`.
6576

6677
### Documentation
6778

docs/AGGREGATES.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Aggregates
22

3-
> Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
3+
Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
44

55
### Methods
66

@@ -53,13 +53,13 @@ Parameter | Type | Default | Description
5353
// ... COUNT( * )
5454
$selectStatement->count();
5555

56-
// ... COUNT( votes ) AS all_votes
56+
// ... COUNT(votes) AS all_votes
5757
$selectStatement->count('votes', 'all_votes');
5858

59-
// ... COUNT( DISTINCT customer_id )
59+
// ... COUNT(DISTINCT customer_id)
6060
$selectStatement->distinctCount('customer_id');
6161

62-
// ... MIN|MAX( salary ) , AVG( price ) , SUM( votes )
62+
// ... MIN|MAX(salary), AVG(price), SUM(votes)
6363
$selectStatement->min('salary');
6464
$selectStatement->max('salary');
6565
$selectStatement->avg('price');

docs/Clause/GROUP_BY.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GROUP BY clause
22

3-
> Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
3+
Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
44

55
### Methods
66

@@ -21,6 +21,5 @@ $selectStatement->groupBy('f_name');
2121
// ... GROUP BY f_name, l_name
2222
$selectStatement->groupBy(['f_name', 'l_name']);
2323
// or
24-
$selectStatement->groupBy('f_name')
25-
->groupBy('l_name');
24+
$selectStatement->groupBy('f_name')->groupBy('l_name');
2625
```

docs/Clause/HAVING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HAVING clause
22

3-
> Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
3+
Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
44

55
### Methods
66

docs/Clause/JOIN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JOIN clause
22

3-
> Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
3+
Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
44

55
### Methods
66

docs/Clause/LIMIT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LIMIT clause
22

3-
> Used in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/DELETE.md) statements.
3+
Used in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/DELETE.md) statements.
44

55
### Methods
66

docs/Clause/OFFSET.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OFFSET clause
22

3-
> Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
3+
Used only in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md) statements.
44

55
### Methods
66

docs/Clause/ORDER_BY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ORDER BY clause
22

3-
> Used in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/DELETE.md) statements.
3+
Used in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/DELETE.md) statements.
44

55
### Methods
66

docs/Clause/WHERE.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# WHERE clause
22

3-
> Used in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/DELETE.md) statements.
3+
Used in [SELECT](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/ParticleBits/PDO/blob/master/docs/Statement/DELETE.md) statements.
44

55
### Methods
66

@@ -143,35 +143,35 @@ Parameter | Type | Default | Description
143143

144144
```php
145145
// ... WHERE usr = ? OR f_name = ?
146-
$statement->where('usr', '=', 'FaaPz')
147-
->orWhere('f_name', '=', 'Fabian');
146+
$stmt->where('usr', '=', 'foobar')
147+
->orWhere('f_name', '=', 'Foo');
148148

149149
// ... WHERE customer_id BETWEEN ? AND ?
150-
$statement->whereBetween('customer_id', [110, 220]);
150+
$stmt->whereBetween('customer_id', [110, 220]);
151151

152152
// ... WHERE customer_id NOT BETWEEN ? AND ?
153-
$statement->whereNotBetween('customer_id', [330, 440]);
153+
$stmt->whereNotBetween('customer_id', [330, 440]);
154154

155-
// ... WHERE customer_id IN ( ?, ?, ?, ? )
156-
$statement->whereIn('customer_id', [110, 120, 130, 140 ]);
155+
// ... WHERE customer_id IN (?, ?, ?, ?)
156+
$stmt->whereIn('customer_id', [110, 120, 130, 140 ]);
157157

158-
// ... WHERE customer_id NOT IN ( ?, ?, ?, ? )
159-
$statement->whereNotIn('customer_id', [112, 124, 136, 148 ]);
158+
// ... WHERE customer_id NOT IN (?, ?, ?, ?)
159+
$stmt->whereNotIn('customer_id', [112, 124, 136, 148 ]);
160160

161161
// ... WHERE f_name LIKE ?
162-
$statement->whereLike('f_name', 'Fab___');
162+
$stmt->whereLike('f_name', 'Foo');
163163

164164
// ... WHERE l_name NOT LIKE ?
165-
$statement->whereNotLike('l_name', 'Lae%');
165+
$stmt->whereNotLike('l_name', 'Bar%');
166166

167167
// ... WHERE f_name IS NULL
168-
$statement->whereNull('f_name');
168+
$stmt->whereNull('f_name');
169169

170170
// ... WHERE l_name IS NOT NULL
171-
$statement->whereNotNull('l_name');
171+
$stmt->whereNotNull('l_name');
172172

173173
// ... WHERE col_1 = ? AND col_2 = ? AND col_3 = ?
174-
$statement->whereMany(
174+
$stmt->whereMany(
175175
[
176176
'col_1' => 'val_1',
177177
'col_2' => 'val_2',

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Documentation
22

3-
> **IMPORTANT!** Before reading through the following commands and methods, please be aware that it is possible to use raw PDO stuff, like `fetch()`, `fetchAll()`, `execute()` and the others whenever you feel you need to.
3+
**IMPORTANT!** Before reading through the following commands and methods, please be aware that it is possible to use raw PDO stuff, like `fetch()`, `fetchAll()`, `execute()` and the others whenever you feel you need to.
44

55
### Statements
66

docs/Statement/DELETE.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ Parameter | Type | Default | Description
2020

2121
```php
2222
// DELETE FROM users WHERE id = ?
23-
$deleteStatement = $db->delete()
24-
->from('users')
25-
->where('id', '=', 1234);
23+
$stmt = $db
24+
->delete()
25+
->from('users')
26+
->where('id', '=', 1234);
2627

27-
$affectedRows = $deleteStatement->execute();
28+
$affectedRows = $stmt->execute();
2829
```

docs/Statement/INSERT.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ Parameter | Type | Default | Description
2929
### Examples
3030

3131
```php
32-
// INSERT INTO users ( usr , pwd ) VALUES ( ? , ? )
33-
$insertStatement = $db->insert(['usr', 'pwd'])
34-
->into('users')
35-
->values(['usr_1', 'pwd_1']);
36-
37-
// INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? )
38-
$insertStatement = $db->insert(['id'])
39-
->into('users')
40-
->columns(['usr', 'pwd'])
41-
->values([1234, 'usr_1234', 'pwd_1234']);
42-
43-
$insertId = $insertStatement->execute(false);
32+
// INSERT INTO users (usr , pwd) VALUES (? , ?)
33+
$stmt = $db
34+
->insert(['usr', 'pwd'])
35+
->into('users')
36+
->values(['usr_1', 'pwd_1']);
37+
38+
// INSERT INTO users (id , usr , pwd) VALUES (? , ? , ?)
39+
$stmt = $db
40+
->insert(['id'])
41+
->into('users')
42+
->columns(['usr', 'pwd'])
43+
->values([1234, 'usr_1234', 'pwd_1234']);
44+
45+
$insertId = $stmt->execute(true); // returns string ID of new row
46+
$pdoStmt = $stmt->execute(false); // returns \PDOStatement
4447
```

docs/Statement/INSERT_MULTI.md

+13-27
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,20 @@ Parameter | Type | Default | Description
3636

3737
### Examples
3838

39-
```php
40-
// INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? )
41-
$insertStatement = $db->insert(['id', 'usr', 'pwd'])
42-
->into('users')
43-
->values([1234, 'your_username', 'your_password']);
44-
45-
// INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? )
46-
$insertStatement = $db->insert(['id'])
47-
->into('users')
48-
->columns(['usr', 'pwd'])
49-
->values([1234, 'your_username', 'your_password']);
50-
51-
$insertId = $insertStatement->execute(false);
52-
```
53-
5439
#### Inserting multiple rows at once
5540

5641
```php
57-
// INSERT INTO users ( usr, pwd ) VALUES ( ? , ? )
58-
// ON DUPLICATE KEY UPDATE pwd = VALUES( pwd )
59-
$insertStatement = $db->insertMulti(['usr', 'pwd'])
60-
->into('users')
61-
->values(
62-
['usr_1', 'pwd_1'],
63-
['usr_2', 'pwd_2'],
64-
['usr_3', 'pwd_3'])
65-
->addRow(['usr_4', 'pwd_4'])
66-
->onDuplicateKeyUpdate(['pwd']);
67-
68-
$affectedRows = $insertStatement->execute();
42+
// INSERT INTO users (usr, pwd) VALUES (? , ?)
43+
// ON DUPLICATE KEY UPDATE pwd = VALUES (pwd)
44+
$stmt = $db
45+
->insertMulti(['usr', 'pwd'])
46+
->into('users')
47+
->values(
48+
['usr_1', 'pwd_1'],
49+
['usr_2', 'pwd_2'],
50+
['usr_3', 'pwd_3']
51+
)->addRow(['usr_4', 'pwd_4'])
52+
->onDuplicateKeyUpdate(['pwd']);
53+
54+
$affectedRows = $stmt->execute(); // returns int
6955
```

docs/Statement/SELECT.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ Parameter | Type | Default | Description
179179

180180
```php
181181
// SELECT * FROM users WHERE id = ?
182-
$selectStatement = $db->select()
183-
->from('users')
184-
->where('id', '=', 1234);
182+
$stmt = $db
183+
->select()
184+
->from('users')
185+
->where('id', '=', 1234)
186+
->execute(); // \PDOStatement
185187

186-
$stmt = $selectStatement->execute();
187188
$data = $stmt->fetch();
188189
```

docs/Statement/UPDATE.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ Parameter | Type | Default | Description
2626

2727
```php
2828
// UPDATE users SET pwd = ? WHERE id = ?
29-
$updateStatement = $db->update(['pwd' => 'your_new_password'])
30-
->table('users')
31-
->where('id', '=', 1234);
29+
$stmt = $db
30+
->update(['pwd' => 'your_new_password'])
31+
->table('users')
32+
->where('id', '=', 1234);
3233

3334
// UPDATE users SET usr = ? , pwd = ? WHERE id = ?
34-
$updateStatement = $db->update(['usr' => 'your_new_username'])
35-
->set(['pwd' => 'your_new_password'])
36-
->table('users')
37-
->where('id', '=', 1234);
35+
$stmt = $db
36+
->update(['usr' => 'your_new_username'])
37+
->set(['pwd' => 'your_new_password'])
38+
->table('users')
39+
->where('id', '=', 1234);
3840

39-
$affectedRows = $updateStatement->execute();
41+
$affectedRows = $stmt->execute();
4042
```

0 commit comments

Comments
 (0)