Recommend this page to a friend!
  Classes of Nahid Bin Azhar  >  Crudx  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Crudx
Store and retrieve objects in MySQL using MySQLi
Author: By
Last change: update readme
Date: 4 years ago
Size: 3,790 bytes



Class file image Download


CRUDX is a PHP based library for mysql query builder. Its easy and simple.

How to install

To install this package go to terminal and run this command

composer require nahid/crudx


To use this package you have to include it. Include it from composer autoload

require_once 'vendor/autoload.php';

How to connect

You can connect by using this process;

use Nahid\Crudx\Crudx;

$config = [
    'host' 		=> 'localhost',
    'user' 		=> 'root',
    'password' 	=> 'your_password',
    'database' 	=> 'database_name',
    'charset' 	=> 'utf8',
    'collation'	=> 'utf8_unicode_ci',
    'prefix' 	=> 'table_prefix',

$crud = new Crudx($config);


Its too much important to inserting data in database table when you developing an application. Crudx make easy to inserting data in table. Crudx provide different type of insertion mechanism. First you can insert data with Laravel Eloquent style. Suppose you want to save name, username, email in users table. So what can you do?


$user->name='Nahid Bin Azhar';


Its like a piece of cake.

The second procedure. Its traditional way. You may called it CodeIgniter Style. However see how can you inserting data with this way.

	'name'=>'Nahid Bin Azhar',


What do you think? yes its Crudx, make easy development.

You may insert multiple records at once. Yes its true, just see what happend

	'name'=>'Nahid Bin Azhar',



Making update rocord is so easy.

	'name'=>'Nahid Bin Azhar',

$crud->where('id', '=', 1)->save($data);


Sometimes you need to delete record from table. Crudx make it easy. Its just a single command

$crud->where('id', '=', 1)->delete();

Fetching Record

Crudx provide you to differents type service to fetching record from table. Suppose you want to get all data of author role from table users

$crud->table('users')->where('role', '=', 'author')->all()->result();

//generated SQL String: SELECT * FROM users WHERE role='author'

But if you want to add multiple condition with AND operator then follow the process

$crud->table('users')->where('role', '=', 'author')->where('age','>',17)->all()->result();

//generated SQL String: SELECT * FROM users WHERE role='author' AND age>17

you can use orWhere() for OR operator and you can also use whereBetween() `orBetween()

If you have to fetch specific table column then use get() method and pass an array to specify table column

$crud->table('users')->where('role', '=', 'author')->get(['name', 'username'])->result();

//generated SQL String: SELECT name, username FROM users WHERE role='author'


Crudx provide you a simple joining method.

$crud->table('posts')->join('users', 'posts.user_id','=', '')->get(['post', 'name'])->result();

//generated SQL String: SELECT post, name FROM posts INNER JOIN users on

Get last inserted id

echo $crud->getId();

Get last generated query string

Sometimes you have to need which query string is generated by the last method. Crudx make it easy

$crud->table('users')->where('role', '=', 'author')->where('age','>',17)->all()->result();
echo $crud->getQueryString();

For more information send a message to info at phpclasses dot org.