A light, efficient and powerful php sql database framework. Allows you to quickly and securely develop anything using SQL databases.
dist/SuperSQL.php
. Minified version: 12.4KB)
SELECT * FROM `table`
is db->select("table");
'[operator1][op2][op3...]column[alias][type]'=>value
$response[0]
will only fetch the first row)You may either
SuperSQL/
, we also provide a simple loader)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.
SELECT * FROM `table`
is just $SuperSQL->select('table');
)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.
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.