Skip to content

Commit ec0275b

Browse files
authored
Update README.md
Updated documentation for version 2.2
1 parent d3937a0 commit ec0275b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

README.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SuperSQL is an easy-to-use powerful SQL query builder for SQLite and MySQL.
66
* PDO SQLite / MySQL driver
77

88
## Setup
9-
* Download the <em>ssql.php</em> file ([https://raw.githubusercontent.com/ratajs/SuperSQL/2.1/ssql.php](https://raw.githubusercontent.com/ratajs/SuperSQL/2.1/ssql.php))
9+
* Download the <em>ssql.php</em> file ([https://raw.githubusercontent.com/ratajs/SuperSQL/2.2/ssql.php](https://raw.githubusercontent.com/ratajs/SuperSQL/2.2/ssql.php))
1010
* Include the file with `include` / `require`
1111

1212
## Examples
@@ -20,23 +20,29 @@ Let’s have a table “<strong>users</strong>” with 5 columns: `uid`, `userna
2020
$ssql = new Ssql("localhost", "root", "root", "db"); // MySQL
2121

2222
//Connect to SQLite with just the first parameter
23-
$ssql = new Ssql("db.sqlite");
23+
$ssql = new Ssql("db.sqlite3");
2424

2525
//To execute raw SQL query use $ssql->q($q[, $a]), FETCH_ALL returns an array of rows, FETCH_OBJECT and FETCH_ARRAY return one row per call
2626
$ssql->q("SELECT * FROM users")->fetch(SQ::FETCH_ALL);
2727

2828
//You can use wildcards for escaping
2929
$ssql->q("SELECT * FROM users WHERE `username`=%0 OR `nickname`=%1", [$name, $nick])->fetch();
3030

31+
//You can set the object‐wide $debug property to print all queries before being executed
32+
$ssql->debug = true;
33+
3134
//You can use queries as methods
3235
$ssql->getUser = "SELECT * FROM users WHERE `username`=%0 OR `nickname`=%1";
3336
$user = $ssql->getUser($name, $nick)->fetch();
3437

35-
//For simple requests use $ssql->read($table[, $flags]) or $ssql->read($table, $cond[, $flags])
38+
//For simple requests use $ssql->read($table[, $cond][, $flags])
3639
//Read function uses FETCH_SMART as default (FETCH_OBJECT for one row, FETCH_ALL for more), so you need to use the FETCH_ALL flag to return an array even when there is only one result
3740
$users = $ssql->read("users", SQ::FETCH_ALL);
3841
$user = $ssql->read("users", ['uid' => $id]);
3942

43+
//You can use the DEBUG flag to print this query before execution
44+
$user = $ssql->read("users", ['uid' => $id], SQ::DEBUG);
45+
4046
//You can use more conditions
4147
$user = $ssql->read("users", ['username' => $name, 'password' => $pass]);
4248

@@ -73,6 +79,15 @@ Let’s have a table “<strong>users</strong>” with 5 columns: `uid`, `userna
7379
//You can delete rows with $ssql->delete($table, $cond[, $flags])
7480
$ssql->delete("users", ['id' => $id]);
7581

82+
//You can use $ssql->put($table, $data[, $cond][, $flags]) for inserting, updating and deleting as well
83+
//Insert
84+
$ssql->put("users", [$id, $name, $pass, time(), NULL]);
85+
$ssql->put("users", ['username' => $name, 'password' => $pass, 'sign_up_time' => time()], SQ::INSERT_RETURN_ID);
86+
//Update
87+
$ssql->put("users", ['nickname' => $nick], ['id' => $id]);
88+
//Delete
89+
$ssql->put("users", NULL, ['id' => $id]);
90+
7691
//Use $ssql->truncate($table[, $flags]) to delete all rows in a table
7792
$ssql->truncate("users");
7893
?>
@@ -94,6 +109,7 @@ Here is list of all SuperSQL flags:
94109
* <b>FETCH_ALL</b>
95110
* <b>FETCH_SMART</b>
96111
* <b>NO_ERROR</b>
112+
* <b>DEBUG</b>
97113

98114
## More examples
99115

@@ -163,6 +179,6 @@ Here is list of all SuperSQL flags:
163179
//You can also pass another condition to it, this will select users that don’t have any nickname with username other than "admin" or "root".
164180
$ssql->read("users", $ssql->cond()->eq("nickname", [""])->not($ssql->cond()->eq("username", ["admin", "root"])));
165181

166-
//Supported condition functions: ->eq(), ->lt(), ->gt(), ->lte(), ->gte(), ->like() and ->between()
182+
//Supported conditions: ->eq(), ->lt(), ->gt(), ->lte(), ->gte(), ->like(), ->between(), ->begins(), ->ends(), ->contains() and ->in()
167183
?>
168184
```

0 commit comments

Comments
 (0)