Skip to content

Commit 7812890

Browse files
committed
Update README.md
1 parent 4c54646 commit 7812890

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

README.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ ___Shortcut Table Methods___
6363
create(string $table = null, ...$schemas);// $schemas requires... column()
6464
column(string $column = null, string $type = null, ...$args);
6565
drop(string $table);
66+
Example
67+
68+
```php
69+
// Creates an database table
70+
create('abc_db',
71+
// and with database column name, datatype
72+
// data types are global CONSTANTS
73+
// SEQUENCE|AUTO is placeholder tag, to be replaced with the proper SQL drivers auto number sequencer word.
74+
column('id', INTR, 11, AUTO, PRIMARY), // mysqli
75+
column('name', VARCHAR, 50, notNULL),
76+
column('email', CHAR, 25, NULLS),
77+
column('phone', TINYINT)
78+
);
79+
```
80+
6681
---
6782

6883
innerJoin(string $leftTable = null, string $rightTable = null,
@@ -101,9 +116,39 @@ prepareOff(); // When off shortcut SQL Methods calls will use vendors escape rou
101116
* `insert(string $table = null, $keyAndValue);`
102117
* `insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$fromWhere);`
103118

104-
---
119+
```php
120+
// Supply the the whole query string, and placing '?' within
121+
// With the same number of arguments in an array.
122+
// It will determine arguments type, execute, and return results.
123+
query_prepared(string $query_string, array $param_array);
124+
```
105125

106-
query_prepared(string $query_string, array $param_array);
126+
#### An Example for using prepare statements indirectly, with above shortcut SQL methods
127+
128+
```php
129+
// To get all shortcut SQL methods calls to use prepare statements
130+
$db->prepareOn(); // This needs to be called at least once at instance creation
131+
132+
$values = [];
133+
$values['name'] = $user;
134+
$values['email'] = $address;
135+
$values['phone'] = $number;
136+
$db->insert('abc_db', $values);
137+
138+
$result = $db->selecting('abc_db', 'phone',
139+
eq('email', $email, _AND), neq('id', 1)
140+
);
141+
142+
foreach ($result as $row) {
143+
echo $row->phone);
144+
}
145+
```
146+
147+
#### An Example for using prepare statements directly, no shortcut SQL methods used
148+
149+
```php
150+
$db->query_prepared('INSERT INTO abc_db( name, email, phone) VALUES( ?, ?, ? )', [$user, $address, $number]);
151+
```
107152

108153
## For Authors and **[Contributors](https://github.com/ezSQL/ezsql/blob/master/CONTRIBUTORS.md)**
109154

0 commit comments

Comments
 (0)