Discontinued.
- MySQLi (100% fully supported)
SlickInject is a PHP
library in which allows you to write fast back-end sites using MySQLi with style. Not only SlickInject increase workflow, but also manages your queries, and make sure you stay secure. SlickInject writes your queries automatically, and protects your database from any leaks & injections.
I would've never made this if I knew a project as of Medoo existed. This project was something I had thought of on my own originally due to the time I wasted in working backend. I never intended to make a project similar, and or better. This is something I use for my personal use. It's small, fast, and lightweight. It wouldn't be public, but decided why not share and have an extra repository. If you like this project, please show appreciation.
Library
- Lib\SlickInject (SlickInject/Parser)
- Lib\SQLObject (SQLObject)
- OR
- build/SlickInject.php
$si = new SlickInject("host", "username", "password", "database_name");
Using SELECT, you will automatically get returned the selected rows in an array format. Check examples for more detailed information.
- The 1st argument
must
be an array.[]
=*
- The 3rd argument
must
be an array, and orNULL
- The 4th argument is
true
by default. Setting itfalse
will returnSlickInject\SQLResponce
(see below).
The example query correlates to the code example of the way you should think when writing.
$si->SELECT([], "table", []); // [] = *, 1st argument (All rows)
- **The 3rd argument as spoke, is WHERE in this case. **
// @param array [] | Columns you're receiving
// @param string "table" | The table name
// @param array array() | WHERE cause
$si->SELECT([], "table", array("id"=>1));
$si->SELECT([], "table", array("id"=>1, "group_id"=>1));
// - or -
$si->SELECT([], "table", array("id"=>1, "AND", "group_id"=>1));
$si->SELECT(["email"], "table", array("ORDER BY", "id"))
$si->SELECT(["email"], "table", array("id"=>1, "ORDER BY", "id"))
$si->SELECT(["email"], "table", array("groud_id"=>1, "`id`>1"));
$si->select_db("otherdatabase")->SELECT([], "table");
Except for the
SELECT
method, the others will return youSQLResponce
, however by default, you are given the rows of the selected data as an array, which can be toggled false as the 4th argument when usingSELECT
$response = $si->SELECT([], "table", [], false);
print_r($response ->num_rows()); // int
$username = "Guest";
$si->UPDATE('users', array("username"=>$username), array("id"=>1));
INSERT INTO `table` (`username`, `email`) VALUES ('Johnny', '[email protected]')
$username = "Johnny";
$email = "[email protected]"
// very simple, and easy.
$si->INSERT('table', array("username"=>$username, "email"=>$email));
$si->DELETE("table", array("id"=>1));
$si->TRUNCATE("table");
When using SlickInject, it does not handle rather or not the connection should be open or closed. Using the statement below, you can close your databse when you're done using it.
$si->close();
-
connect(string, string, string, string) :: void : Connect to databse.
-
getConnectionError() :: integer : Get database connection status error code
-
getLastError() :: string : Get last database error
-
ping() :: bool : Return if connection is still live and not closed.
-
query(string, array||null, bool) :: void : Shouldn't be used unless you know what you're doing.
-
hasRows() :: bool : If query returned any rows
-
getResult() :: object : Returns mysqli_query responce
-
num_rows() :: integer : Return number of rows
-
getData() :: array : Return query table row(s)
-
didAffect() :: bool : If any rows was affected during execution
-
error() :: bool : If result doesn't exist or contain any errors