A light, efficient and powerful php sql database framework. Allows you to quickly and securely develop anything using SQL databases.
- To provide a very fast and efficient way to use SQL databases.
- To provide an easy way to use SQL databases safely.
- Very small - 27.4KB one file (Unminified,
dist/SuperSQL.php
. Minified version: 12.4KB)- You can also choose whether you want an optional helper class.
- Simple and easy - Very easy to learn. SuperSQL was designed to be easy and simple, to the point that a noob can use it.
- Straight forward syntax
SELECT * FROM `table`
isdb->select("table");
- String syntax is standardised. Its allways
'[operator1][op2][op3...]column[alias][type]'=>value
- Straight forward syntax
- Compatability - Supports all major SQL databases
- Uses the PDO API for widespread support
- Efficiency - This module was built with speed and efficiency in mind.
- Internal optimizations to make sure there is little overhead as possible
- Dynamic SQLResponse class so you only fetch a row when you use it (
$response[0]
will only fetch the first row)
- Complexity - This module allows you to make all kinds of complex queries.
- Multi-table queries to execute queries on multiple tables at once
- Multi-value queries to execute queries with multiple values
- Templates to pass sets of data in as a group
- Type casting and aliases
- DISTINCT, GROUP, LIMIT/OFFSET, INSERT [INTO], and more supported
- Raw input available
- Security - This module prevents SQL injections, so hackers bye bye!
- Uses PDO's prepare/bindParam/execute system with types
- Availability & Integration - This module is FREE. Licensed under the MIT license.
- Use it as you wish! Only remember to give credit.
- Also available on composer
You may either
- Use the built file (/dist/SuperSQL.php - preferred)
- Use the library (Autoload all in
SuperSQL/
, we also provide a simple loader) - Use the composer package (
composer require threeletters/supersql
)
new SuperSQL($dsn,$user,$pass);
use SuperSQL\SuperSQL;
// MySql setup
$host = "localhost";
$db = "test";
$user = "root";
$pass = "1234";
$dsn = "mysql:host=$host;port=3306;dbname=$db;charset=utf8";
$SuperSQL = new SuperSQL($dsn,$user,$pass);
use SuperSQL\SQLHelper;
// MySql setup
$host = "localhost";
$db = "test";
$user = "root";
$pass = "1234";
$SuperSQL = SQLHelper::connect($host, $db, $user,$pass);
$result = $SuperSQL->select("test",[],[
"condition" => 12345,
"[||][&&]" => [
"something" => "value",
"anotherthing" => "val"
]
]); // SELECT * FROM `test` WHERE `condition` = 12345 OR (`something` = 'value' AND `anotherthing` = 'val')
if (!$result->error()) {
foreach ($result as $val) { // NOTE, $result is NOT an array
echo $val;
}
} else {
echo json_encode($result->error());
}
To build this library, you need NodeJS. Then execute builder.js
node builder.js
It will build to /dist/SuperSQL*.php
Full documentation is here: https://threeletters.github.io/SuperSQL
What is a SQLResponse?
SQLResponse is the object returned from a query. It implements the ArrayAccess and Iterator interfaces, and so can be accessed and iterated through like an array. When you do access a row or iterate through, a function is called and fetches the row from the database, and caches it. If all rows are fetched, then the connection is deleted as it does not have to be used anymore.
Whats the difference between this and Medoo?
While on the most basic level, SuperSQL and Medoo are the same, they are quite different.
- Response class - SuperSQL has a response class to access crucial information, such as errors
- Helper - SuperSQL comes with an optional advanced helper class, with helper functions, while medoo has a simple one built right in.
- Smaller & lightweight - SuperSQL is smaller than Medoo, yet has more features.
- Development - SuperSQL's code is well structured and it is commented - so you can understand it more
- SuperSQL is faster - Using xdebug, we found that superSQL's parser is faster than medoo's. (x1000,100%)
- SuperSQL is less confusing. (EG,
SELECT * FROM `table`
is just$SuperSQL->select('table');
) - SuperSQL has more features - (EG, multi-querying, dynamic responses, distinct, etc...)
How fast is superSQL compared to Medoo?
Whats the difference between this an SlickInject?
SuperSQL uses the same concepts and design as SlickInject. However, SuperSQL has more complex features.
Why use PDO instead of Mysqli?
PDO is much more versatile than mysqli. Main reason is because it supports so many different databases while mysqli only supports one.
How did you make the documentation?
The nice documentation was created using Slate - Check it out.
- @LegitSoulja - SlickInject,
- @catfan - Medoo
- Slate (Documentation)
Contributing is open. If you want to contribute, make a pull request. Please use the PEAR format.
NOTE: please do not do
[]
for array. Please usearray()
instead. This is for backwards compatability.
MIT License
Copyright (c) 2017 Andrew S (Andrews54757_at_gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.