Skip to content

Commit 68ad2de

Browse files
authored
Update README.md
Correct some mistakes and update some things based on PR #3
1 parent 4201854 commit 68ad2de

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ if ($db->connected()) {
9999
In order to get data from the database you can use the method `select()` in the following format:
100100

101101
```php
102-
select(string $sql, $where=null, $fetch_mode=PDO::FETCH_ASSOC)
102+
select(string $sql, array $where=null, int $fetch_mode=PDO::FETCH_ASSOC)
103103
```
104104

105105
The following arguments exist:
@@ -110,19 +110,21 @@ The sql to perform the query to the database. (required)
110110
For example:
111111

112112
```sql
113-
SELECT * FROM `users`
113+
SELECT * FROM `users` WHERE `username` = :username
114114
```
115115

116-
#### SQL Where Clause (`$where`)
117-
The sql where clause to filter the data from the database and so on. (optional)
116+
#### Values for Where Clause (`$where`)
117+
An array of the values to use in the where clause. (optional)
118118

119119
Default: `null`
120120

121121
Example:
122-
```sql
123-
WHERE `username` = 'Jack'
122+
```php
123+
[ 'username' => 'Jack' ]
124124
```
125125

126+
Please note that you have to provide an associative array with keys that match to the placeholders in the sql query, unless you are not using the named placeholders in the query. In case you are just using the question marks as the placeholder, you can get rid of the keys.
127+
126128
#### PDO Fetch Mode (`$fetch_mode`)
127129
The [pdo fetch mode](http://php.net/manual/en/pdostatement.fetch.php). Defines in which format the data is returned from the database. (optional)
128130

@@ -137,7 +139,7 @@ PDO::FETCH_NUM
137139
An simple example for using everything together:
138140

139141
```php
140-
$data = $db->select("SELECT * FROM `users`", "WHERE `username` = 'Jack'", PDO::FETCH_NUM);
142+
$data = $db->select("SELECT * FROM `users` WHERE `username` = :username", [ 'username' => 'Jack' ], PDO::FETCH_NUM);
141143
```
142144

143145
### Insert Data into Database (`insert()`)
@@ -190,7 +192,7 @@ The method `delete()` provides the ability to delete data from the database.
190192
You have to follow this format:
191193

192194
```php
193-
delete(string $sql, $where=null)
195+
delete(string $sql, array $where=null)
194196
```
195197

196198
These are the existing arguments:
@@ -227,7 +229,7 @@ $deleted = $db->delete("DELETE FROM `users` WHERE `id` = :id", [ 'id' => 3 ]);
227229
You can update data in your database by the method `update()`, which has this format:
228230

229231
```php
230-
update(string $sql, $values)
232+
update(string $sql, array $values)
231233
```
232234

233235
That leads to the following arguments:

0 commit comments

Comments
 (0)