Skip to content
This repository has been archived by the owner on Feb 21, 2018. It is now read-only.
/ SlickInject Public archive

SQL Helper / Make Life Easier

License

Notifications You must be signed in to change notification settings

segg21/SlickInject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SlickInject!

::v2

Discontinued.

Supports PHP (v5.6 - v7.1)

  • 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.

Installation

Library

  • Lib\SlickInject (SlickInject/Parser)
  • Lib\SQLObject (SQLObject)
  • OR
  • build/SlickInject.php

Connect to database.

$si = new SlickInject("host", "username", "password", "database_name");

SELECT

Using SELECT, you will automatically get returned the selected rows in an array format. Check examples for more detailed information.

Notes about SELECT
  • The 1st argument must be an array. [] = *
  • The 3rd argument must be an array, and or NULL
  • The 4th argument is true by default. Setting it false will return SlickInject\SQLResponce (see below).

The example query correlates to the code example of the way you should think when writing.

SELECT * FROM `table`
$si->SELECT([], "table", []); // [] = *, 1st argument (All rows)
SELECT * FROM `table` WHERE `id` = 1

Notes about WHERE

  • **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));
SELECT * FROM `table` WHERE `id`=1 AND `group_id`=1
$si->SELECT([], "table", array("id"=>1, "group_id"=>1));

// - or - 

$si->SELECT([], "table", array("id"=>1, "AND", "group_id"=>1));
SELECT `email` FROM `table` ORDER BY id
$si->SELECT(["email"], "table", array("ORDER BY", "id"))
SELECT `email` FROM `table` WHERE id = 1 ORDER BY id
$si->SELECT(["email"], "table", array("id"=>1, "ORDER BY", "id"))
SELECT `email` FROM `table` WHERE `group_id`=1 AND `id` > 1
$si->SELECT(["email"], "table", array("groud_id"=>1, "`id`>1"));
Change database
$si->select_db("otherdatabase")->SELECT([], "table"); 
SQLResponce | SELECT (Example)

Except for the SELECT method, the others will return you SQLResponce, 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 using SELECT

Obtain number of rows
$response = $si->SELECT([], "table", [], false);

print_r($response ->num_rows()); // int

UPDATE

UPDATE `table` SET `username`="Guest" WHERE `id`=1
$username = "Guest";

$si->UPDATE('users', array("username"=>$username), array("id"=>1));

INSERT

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));

DELETE

DELETE FROM `table` WHERE `id`=1
$si->DELETE("table", array("id"=>1));

TRUNCATE

TRUNCATE TABLE `table`
$si->TRUNCATE("table");

Closing Database

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();

SQLObject

Functions | Return | Description

  • 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.

SQLResponce

Functions | Return | Description

  • 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