Skip to content

Commit 8012893

Browse files
authored
Update README.md
1 parent 68c8a79 commit 8012893

File tree

1 file changed

+69
-43
lines changed

1 file changed

+69
-43
lines changed

README.md

+69-43
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,81 @@
1-
# Super MySQL
2-
Super MySQL is an easy-to-use powerful SQL query builder.
1+
# SuperSQL
2+
SuperSQL is an easy-to-use powerful SQL query builder for SQLite and MySQL.
33

44
## Requirements
55
* PHP 5.6+
6-
* MySQL
7-
* PDO MySQL extension
6+
* PDO SQLite / MySQL driver
87

98
## Examples
109
Let’s have a table “<strong>users</strong>” with 5 columns: `uid`, `username`, `password`, `sign_up_time` and `nickname`
1110

1211
```php
1312
<?php
14-
include "smysql.php";
13+
include "ssql.php";
1514

16-
//Connect with new Smysql($host, $user, $password[, $database])
17-
$smysql = new Smysql("localhost", "root", "root", "db");
15+
//Connect with new Ssql($host[, $user[, $password[, $database]]])
16+
$ssql = new Ssql("localhost", "root", "root", "db");
1817

19-
//To execute raw SQL query use $smysql->q($q[, $a]), FETCH_ALL returns an array of rows, FETCH_OBJECT and FETCH_ARRAY return one row per call
20-
$smysql->q("SELECT * FROM users")->fetch(SMQ::FETCH_ALL);
18+
//Connect to SQLite with just the first parameter
19+
$ssql = new Ssql("db.sqlite");
20+
21+
//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
22+
$ssql->q("SELECT * FROM users")->fetch(SMQ::FETCH_ALL);
2123

2224
//You can use wildcards for escaping
23-
$smysql->q("SELECT * FROM users WHERE `username`=%0 OR `nickname`=%1", [$name, $nick])->fetch();
25+
$ssql->q("SELECT * FROM users WHERE `username`=%0 OR `nickname`=%1", [$name, $nick])->fetch();
2426

2527
//You can use queries as methods
26-
$smysql->getUser = "SELECT * FROM users WHERE `username`=%0 OR `nickname`=%1";
27-
$user = $smysql->getUser($name, $nick)->fetch();
28+
$ssql->getUser = "SELECT * FROM users WHERE `username`=%0 OR `nickname`=%1";
29+
$user = $ssql->getUser($name, $nick)->fetch();
2830

29-
//For simple requests use $smysql->read($table[, $flags]) or $smysql->read($table, $cond[, $flags])
31+
//For simple requests use $ssql->read($table[, $flags]) or $ssql->read($table, $cond[, $flags])
3032
//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
31-
$users = $smysql->read("users", SMQ::FETCH_ALL);
32-
$user = $smysql->read("users", ['uid' => $id]);
33+
$users = $ssql->read("users", SMQ::FETCH_ALL);
34+
$user = $ssql->read("users", ['uid' => $id]);
3335

3436
//You can use more conditions
35-
$user = $smysql->read("users", ['username' => $name, 'password' => $pass]);
37+
$user = $ssql->read("users", ['username' => $name, 'password' => $pass]);
3638

3739
//You can use the COND_OR flag for OR operator instead of AND
38-
$user = $smysql->read("users", ['username' => $name, 'nickname' => $nick], SMQ::FETCH_ALL | SMQ::COND_OR)[0];
40+
$user = $ssql->read("users", ['username' => $name, 'nickname' => $nick], SMQ::FETCH_ALL | SMQ::COND_OR)[0];
3941

4042
//You can use custom conditions
41-
$users = $smyslq->read("users", "`sign_up_time` > " . bcsub(time(), 3600));
43+
$users = $ssql->read("users", "`sign_up_time` > " . bcsub(time(), 3600));
4244

4345
//You can use more of them
44-
$users = $smyslq->read("users", ["`sign_up_time` > " . bcsub(time(), 3600), "`nickname` IS NOT NULL"], SMQ::FETCH_ALL);
46+
$users = $ssql->read("users", ["`sign_up_time` > " . bcsub(time(), 3600), "`nickname` IS NOT NULL"], SMQ::FETCH_ALL);
4547

46-
//For more complicated requests use $smysql->select($table[, $order[, $cols[, $limit[, $flags]]]]), you can use array keys for aliases
47-
$users = $smysql->select("users", "sign_up_time", ['id' => "uid", 'name' => "username", "sign_up_time", "nickname"], NULL, SMQ::ORDER_DESC)->fetch(SMQ::FETCH_ALL);
48+
//For more complicated requests use $ssql->select($table[, $order[, $cols[, $limit[, $flags]]]]), you can use array keys for aliases
49+
$users = $ssql->select("users", "sign_up_time", ['id' => "uid", 'name' => "username", "sign_up_time", "nickname"], NULL, SMQ::ORDER_DESC)->fetch(SMQ::FETCH_ALL);
4850

49-
//Or $smysql->selectWhere($table, $cond[, $order[, $cols[, $limit[, $flags]]]])
50-
$user = $smysql->selectWhere("users", ['uid' => $id], "name", ['id' => "uid", 'name' => "username", "sign_up_time", 'nick' => "nickname"])->fetch();
51+
//Or $ssql->selectWhere($table, $cond[, $order[, $cols[, $limit[, $flags]]]])
52+
$user = $ssql->selectWhere("users", ['uid' => $id], "name", ['id' => "uid", 'name' => "username", "sign_up_time", 'nick' => "nickname"])->fetch();
5153

5254
//To quickly display tables use ->dump()
53-
$smysql->select("users")->dump();
55+
$ssql->select("users")->dump();
5456

55-
//Insert with $smysql->insert($table, $values[, $flags])
56-
$smysql->insert("users", [$id, $name, $pass, time(), NULL]);
57+
//Insert with $ssql->insert($table, $values[, $flags])
58+
$ssql->insert("users", [$id, $name, $pass, time(), NULL]);
5759

5860
//You can use array keys as col names
59-
$smysql->insert("users", ['username' => $name, 'password' => $pass, 'sign_up_time' => time()]);
61+
$ssql->insert("users", ['username' => $name, 'password' => $pass, 'sign_up_time' => time()]);
6062

6163
//You can use INSERT_RETURN_ID flag for returning the first auto increment col value (depends on the database type)
62-
$id = $smysql->insert("users", ['username' => $name, 'password' => $pass, 'sign_up_time' => time()], SMQ::INSERT_RETURN_ID);
64+
$id = $ssql->insert("users", ['username' => $name, 'password' => $pass, 'sign_up_time' => time()], SMQ::INSERT_RETURN_ID);
6365

64-
//Use $smysql->update($table, $cond, $values[, $flags]) to update rows
65-
$smysql->update("users", ['id' => $id], ['nickname' => $nick]);
66+
//Use $ssql->update($table, $cond, $values[, $flags]) to update rows
67+
$ssql->update("users", ['id' => $id], ['nickname' => $nick]);
6668

67-
//You can delete rows with $smysql->delete($table, $cond[, $flags])
68-
$smysql->delete("users", ['id' => $id]);
69+
//You can delete rows with $ssql->delete($table, $cond[, $flags])
70+
$ssql->delete("users", ['id' => $id]);
6971

70-
//Use $smysql->truncate($table[, $flags]) to delete all rows in a table
71-
$smysql->truncate("users");
72+
//Use $ssql->truncate($table[, $flags]) to delete all rows in a table
73+
$ssql->truncate("users");
7274
?>
7375
```
7476

7577
## Flags
76-
Here is list of all Super-MySQL flags:
78+
Here is list of all SuperSQL flags:
7779
* <b>ORDER_ASC</b>
7880
* <b>ORDER_DESC</b>
7981
* <b>JOIN_INNER</b>
@@ -93,27 +95,51 @@ Here is list of all Super-MySQL flags:
9395

9496
```php
9597
<?php
96-
//To use the same database in more projects you can extend the Smysql class
97-
class mySmysql extends Smysql {
98+
//To use the same database in more projects you can extend the Ssql class
99+
class mySsql extends Ssql {
98100
protected $host = "localhost";
99101
protected $user = "root";
100102
protected $password = "root";
101103
protected $db = "db"; //Optional
102104
};
103105
//And then create an instance
104-
$smysql = new mySmysql();
106+
$ssql = new mySsql();
105107
//If $db is not set, you can set it afterwards
106-
$smysql->changeDb("newDB");
108+
$ssql->changeDb("newDB");
107109

108110

109111
//Join
110112

111113

112-
//Use $smysql->selectJoin($table, $join, $on[, $order[, $cols[, $limit[, $flags]]]]) to execute a JOIN command
113-
$result = $smysql->selectJoin("users", "messages", ['from_user' => 'uid'], "time", "*", 5, SMQ::ORDER_DESC)->fetch(SMQ::FETCH_ALL);
114+
//Use $ssql->selectJoin($table, $join, $on[, $order[, $cols[, $limit[, $flags]]]]) to execute a JOIN command
115+
$result = $ssql->selectJoin("users", "messages", ['from_user' => 'uid'], "time", "*", 5, SMQ::ORDER_DESC)->fetch(SMQ::FETCH_ALL);
114116
//Use JOIN_LEFT, JOIN_RIGHT and JOIN_FULL flags to other types of JOIN
115117

116-
//To combine JOIN and WHERE use $smysql->selectJoinWhere($table, $join, $on, $cond[, $order[, $cols[, $limit[, $flags]]]])
117-
$result = $smysql->selectJoinWhere("users", "messages", ['from_user' => 'uid'], ['from_user' => $uid])->fetch(SMQ::FETCH_ALL);
118+
//To combine JOIN and WHERE use $ssql->selectJoinWhere($table, $join, $on, $cond[, $order[, $cols[, $limit[, $flags]]]])
119+
$result = $ssql->selectJoinWhere("users", "messages", ['from_user' => 'uid'], ['from_user' => $uid])->fetch(SMQ::FETCH_ALL);
120+
121+
122+
123+
//Table creation and deletion
124+
125+
126+
//For basic table creation use $ssql->createTable($table, $params[, $primary[, $flags]])
127+
$ssql->createTable("myTable", [
128+
'number' => [ // Column name
129+
'type' => "int", // Column type
130+
'NULL' => false // NULL
131+
],
132+
'text' => [
133+
'type' => "varchar",
134+
'length' => 64, // Max length
135+
'NULL' => true
136+
]
137+
], "number");
138+
139+
//Use $ssql->deleteTable($table[, $flags]) to delete a table
140+
$c->deleteTable("myTable");
141+
142+
//To see a list of all tables in your database use $ssql->tableList([$flags])
143+
$c->tableList();
118144
?>
119145
```

0 commit comments

Comments
 (0)