Config | Auth | CRUD | Session – OOP MySqli Php library

Here i am going to discuss about a small OOP PHP library. It is very simple Library with great functionality, For programmers it is very easily to understand. I included 4 basic classes that are listed below.

  1. Database Class  – Connection and Disconnection MySqli
  2. Authentication Class – Login, Authentication
  3. Crud Class – Select, insert, update, delete
  4. Session Class – Session data  

Database Class Configuration (Database.Class.php)

In the database file user must specify the username, password, Database name, and host name.

You can get the connection by calling like below.

In the constructor method inside the database class calls the connect method. The connect method first check if the connection already made or not. if connection exist, it returns connection. if not exist the method connect() trying  to connect the Mysql and returns the connection.

Constructor –  To connect the MySql by calling Connect()

Connect() – Connect to MySql & returns Connection.

Disconnect() – Disconnect to MySql.

Session Class (Session.class.php)

Session class have 5 static methods. we can call them  session::method.

start() – Start the session.  call by Session::start()

set($key, $value) – set session value.   call by Session::set(‘key’ ,’value’);

get($key,$second_key) – The second parameter is not necessary. It is useful for Session key have Array values.

You can retrieve specific session key value by calling session::get(‘key’)

display() – Display all session values. call by session::display()

destroy() – Destroys all session values. call by Session::destroy()

MySqli – CRUD Class (Crud.class.php)

The Crud class handles four main functions.

  • Insert Data to Table
  • Select Data From Table
  • Update Data into Table
  • Delete Table Data

Constructor – Constructor creates a instance for database.

Destructor – Destruct the connection after use.

select($table , $conditions=[]) – Select method which select the data from the table. The method dynamically creates sql query by the conditions provided by the user. Select conditions must passed by array of elements. The supported array keys are select,where, start, limit, return_type. You can set the corresponding value to the array key. The Where key values must be in another array. The example are provided in the above select method.

insert($table, $data ) –  Insert method which insert the data to the specified table. The $table stands for table name and $data Stands for the the to be inserted. The data should be in array format like below.

update($table,$set,$where) – update method update the values in specified fields with the where data. Three parameters needed. $table for table name, $set for update Data and $where for Where data. The Syntax follows.

delete($table, $where) – Here there is 2 parameters can passed to the delete method. The Second parameter is not necessary. The Where parameter stands for specify which data has to be deleted. syntax as follows.

note: If there is no $whereData you provided, The whole data inside the table will deleted.

 

 

Authentication Class (Auth.class.php)

The Auth class works by the support of Crud.class.php , Database Class And Session Class. This class includes a constructor method and 4 other methods.

 

Constructor – Creates the Object for Crud.class and Database.class

 

random( $l ,’Any_random_String’ ) – Random string generates.   You can pass 2 parameters. (not necessary)

length – length of the generated string.

String – Which Letters Have to be contain in the output string.
passHash($data) –  Hash the password with BCRYPT.

 

login($table_name, $user_name , $pass_word) –   username and password must be array.

 

 

newUser($table_name , $data_array, $pass_array) –   Data and Pass must be array.

In the array contain Table attribute name, Value , and type of the value for binding .( i =>integer , d =>double , s=>string, b=>blob )

 

 

The entire library available in Github. You can Download it from there.

Summary
Article Name
Config | Auth | CRUD | Session - OOP MySqli Php library
Description
Here i am going to discuss about a small OOP PHP library. I included 4 basic classes that are listed below. Session, database, crud,Auth functionalities
Author

Jees K Denny

I’m Jees K Denny, a Web Developer and a Passionate Blogger from Pudukad, Thrissur, Kerala. You can get in touch with me In most of your social networks including Facebook , Google , Twitter etc.

Leave a Reply