PHP code example of nahid / crudx

1. Go to this page and download the library: Download nahid/crudx library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nahid / crudx example snippets




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

$user=$crud->table('users');

$user->name='Nahid Bin Azhar';
$user->username='nahid';
$user->email='[email protected]';

$user->save();

$data=[
	'name'=>'Nahid Bin Azhar',
	'username'=>'nahid',
	'email'=>'[email protected]'
];

$crud->table('users')->save($data);

$data=[
	[
	'name'=>'Nahid Bin Azhar',
	'username'=>'nahid',
	'email'=>'[email protected]'
	],
	[
	'name'=>'Naim',
	'username'=>'naim',
	'email'=>'[email protected]'
	]
];

$crud->table('users')->insertMany($data);

$data=[
	'name'=>'Nahid Bin Azhar',
	'username'=>'nahid',
	'email'=>'[email protected]'
];

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

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

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

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

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

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

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

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

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

//generated SQL String: SELECT post, name FROM posts INNER JOIN users on posts.user_id=users.id

$crud->table('users')->save(['name'=>'Nahid']);
echo $crud->getId();

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