Skip to content

Commit 49e201b

Browse files
authored
Updated examples
1 parent 9af684a commit 49e201b

1 file changed

Lines changed: 31 additions & 14 deletions

File tree

README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ $db->select("column FROM table");
3131

3232
To select data based on user data instead of passing the data to the query directly use a prepared statement, this is safer and stops any attempt at sql injections.
3333

34+
**Names placeholders**
35+
3436
```php
35-
$db->select("username FROM members WHERE memberID = :id and email = :email", array(':id' => 1, ':email' => 'someone@domain.com'));
37+
$db->select("username FROM members WHERE id = :id and email = :email", array(':id' => 1, ':email' => 'someone@domain.com'));
3638
```
3739

38-
The above query will return the username from the members table where the memberID and email match. The memberID and email is passed seperartly in an array.
40+
**Annonomus placeholders**
41+
42+
```php
43+
$db->find("username FROM members WHERE id=? and email =?", [1, 'someone@domain.com']);
44+
```
45+
46+
The above query will return the username from the members table where the id and email match. The id and email is passed seperartly in an array.
3947

4048
Instead of passing in an id and email to the query directly a placeholder is used :id and :email then an array is passed the keys in the array matches the placeholder and is bound, so the database will get both the query and the bound data.
4149

@@ -54,10 +62,18 @@ foreach ($rows as $row) {
5462

5563
Using find() will return only a single result. Like select it accepts params being passed in an array as a second argument.
5664

65+
**Names placeholders**
66+
5767
```php
5868
$db->find("column FROM table where id=:id", [':id' => 23]);
5969
```
6070

71+
**Annonomus placeholders**
72+
73+
```php
74+
$db->find("column FROM table where id=?", [23]);
75+
```
76+
6177
# Raw
6278

6379
A raw query is a query that is not ran through a prepared statement and will execute the query passed directly. Useful when creating a table.
@@ -77,11 +93,11 @@ $db->raw("CREATE TABLE IF NOT EXISTS members (
7793
Data is inserted by calling the insert method it expects the table name followed by an array of key and values to insert in to the database.
7894

7995
```php
80-
$data = array(
96+
$data = [
8197
'firstName' => 'Joe',
8298
'lastnName' => 'Smith',
8399
'email' => 'someone@domain.com'
84-
);
100+
];
85101
$db->insert('members', $data);
86102
```
87103

@@ -96,25 +112,27 @@ $id = $db->insert('members', $data);
96112
To update an existing record the update method is called. This method expects the table, array of data to update and a second array containing the where condition.
97113

98114
```php
99-
$data = array(
115+
$data = [
100116
'firstName' => 'Joe',
101117
'lastnName' => 'Smith',
102118
'email' => 'someone@domain.com'
103-
);
104-
$where = array('memberID' => 2);
119+
];
120+
$where = ['memberID' => 2];
105121
$db->update('members', $data, $where);
106122
```
107123
Or:
108124

109125
```php
110-
$update = array(
111-
'data'=>array(
126+
$update = [
127+
'data' => [
112128
'firstName' => 'Joe',
113129
'lastnName' => 'Smith',
114130
'email' => 'someone@domain.com'
115-
),
116-
'where'=> array('memberID' => 2)
117-
);
131+
],
132+
'where' => [
133+
'memberID' => 2
134+
]
135+
];
118136

119137
$db->update('members', $update['data'], $update['where']);
120138

@@ -125,7 +143,7 @@ $db->update('members', $update['data'], $update['where']);
125143
To delete records call the delete method. This method expects the table name and an array of the where condition.
126144

127145
```php
128-
$where = array('memberID' => 2);
146+
$where = ['memberID' => 2];
129147
$db->delete('members', $where);
130148
```
131149

@@ -166,4 +184,3 @@ If table has no column `id`
166184
```php
167185
$db->count('members', 'member_id');
168186
```
169-

0 commit comments

Comments
 (0)