You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-14Lines changed: 31 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,11 +31,19 @@ $db->select("column FROM table");
31
31
32
32
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.
33
33
34
+
**Names placeholders**
35
+
34
36
```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'));
36
38
```
37
39
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.
39
47
40
48
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.
41
49
@@ -54,10 +62,18 @@ foreach ($rows as $row) {
54
62
55
63
Using find() will return only a single result. Like select it accepts params being passed in an array as a second argument.
56
64
65
+
**Names placeholders**
66
+
57
67
```php
58
68
$db->find("column FROM table where id=:id", [':id' => 23]);
59
69
```
60
70
71
+
**Annonomus placeholders**
72
+
73
+
```php
74
+
$db->find("column FROM table where id=?", [23]);
75
+
```
76
+
61
77
# Raw
62
78
63
79
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 (
77
93
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.
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.
0 commit comments