PHPackages                             mg3lo/mysql-crud - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mg3lo/mysql-crud

ActiveLibrary[Database &amp; ORM](/categories/database)

mg3lo/mysql-crud
================

MySql Crud Library

v1.0.0(3y ago)1381MITPHP

Since Mar 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/markusoft/mysql-crud)[ Packagist](https://packagist.org/packages/mg3lo/mysql-crud)[ RSS](/packages/mg3lo-mysql-crud/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (1)

What is MySql CRUD
==================

[](#what-is-mysql-crud)

[MySql Crud](https://github.com/markusoft/mysql-crud) is a Plug and Play PHP Library created to Auto-magically build CRUD capabilities for your MySql Database. Although it has similarities with Query Builder and Eloquent ORM but on Steroids, it is not meant to replace them but to complement and work in conjuction with them.

Easy Peasy Summary
==================

[](#easy-peasy-summary)

[Basic Functionalities](#basic-functionalities)

FunctionCodeDescription[table($db\_table)](#table)$crud-&gt;table('products')Sets database table[find($id)](#find)$crud-&gt;find(1)Retrieve records with id = 1[add($records)](#add)$crud-&gt;add($records)Add record/s[edit(records)](#edit)$crud-&gt;edit($records)Edit record/s[delete($ids)](#delete)$crud-&gt;delete($ids)Delete record/s[get()](#get)$crud-&gt;table('products')-&gt;get()Executes get queries[reset()](#reset)$crud-&gt;reset()Reset Query[close()](#close)$crud-&gt;close()Close database connection[Query Builder](#query-builder)

FunctionCodeDescription[where()](#where)$crud-&gt;where('id', 1)Adds where clause[where\_raw($sql)](#where-raw)$crud-&gt;where\_raw($sql)Adds raw where clause[or\_where()](#or-where)$crud-&gt;or\_where('status', 'active')Add or where clause[where\_in($column, $in)](#where-in)$crud-&gt;where\_in('id', \[1,2,3\])Add where in clause[or\_where\_in($column, $in)](#or-where-in)$crud-&gt;or\_where\_in('id', \[1,2,3\])Add or where in clause[where\_not\_in($column, $in)](#where-not-in)$crud-&gt;where\_not\_in('id', \[1,2,3\])Add or where not in clause[like($column, $like)](#like)$crud-&gt;like('name', 'iphone')Add like clause[or\_like($column, $like)](#or-like)$crud-&gt;or\_like('name', 'iphone')Add or like clause[having()](#having)$crud-&gt;having('status', 'active')Add having clause[or\_having()](#or-having)$crud-&gt;or\_having('status', 'active')Add or having clause[having\_in($column, $in)](#having-in)$crud-&gt;having\_in('id', \[1,2,3\])Add having in clause[or\_having\_in($column, $in)](#or-having-in)$crud-&gt;or\_having\_in('id', \[1,2,3\])Add or having in clause[having\_not\_in($column, $in)](#having-not-in)$crud-&gt;having\_not\_in('id', \[1,2,3\])Add or having not in clause[group\_by($group)](#group-by)$crud-&gt;group\_by('status')Add group by clause[sort or order\_by($sort, $order')](#order-by)$crud-&gt;order\_by('name', 'asc')Add order by clause[take or limit($limit, $offset)](#limit)$crud-&gt;limit(100)Add limit clause[skip or offset($offset)](#offset)$crud-&gt;offset(100)Add offset clause[Advance Get Functionalities](#advance-get-functionalities)

FunctionCodeDescription[search($search, $columns)](#search)$crud-&gt;search('ipone', \['name', 'description'\])Search tables[filter()](#filter)$crud-&gt;filter()Adds filters from url limit, sort etc[query or raw()](#raw)$crud-&gt;raw('SELECT \* FROM products')Creates a raw sql query[filter\_query or filter\_raw()](#filter-raw)$crud-&gt;filter\_raw()Filters raw sql query[switch\_case($case)](#switch-case)$crud-&gt;switch\_case('pascal')Changes record cases[Advance Get Related Functionalities](#advance-get-related-functionalities)

FunctionCodeDescription[with($table)](#with)$crud-&gt;with('products')Retrieves related records[with\_recursive($table, $recursive\_options)](#with-recursive)$crud-&gt;with\_recursive('categories')with\_recursive('categories')[where\_with($table, $callback)](#where-with)$crud-&gt;where\_with('products', static function($query){ return $query-&gt;where('status', 'active'); })Work with related table[where\_pivot($table, $callback)](#where-pivot)$crud-&gt;where\_pivot('categories', static function($query){ return $query-&gt;where('status', 'active'); })Work with pivot tables[where\_with\_pivot($table, $callback, $pivot\_callback)](#where-with-pivot)$crud-&gt;where\_with\_pivot('categories', static function($query){ return $query-&gt;where('status', 'active'); })Work with related and pivot tables[with\_custom($name, $callback)](#with-custom)$crud-&gt;with\_custom('any', static function($record){ return $record\['foo'\] = 'bar'; })Add or edit anything on records[has($table)](#has)$crud-&gt;has('products')Queries only records that has[where\_has($table, $callback)](#where-has)$crud-&gt;where\_has('products', static function($query){ return $query-&gt;where('status', 'active'); })Queries only records that has and filtered more[has\_no($table)](#has-no)$crud-&gt;has\_no('products')Queries only records that has no[where\_has\_no($table, $callback)](#where-has-no)$crud-&gt;where\_has\_no('products', , static function($query){ return $query-&gt;where('status', 'active'); })Queries only records that has no and filtered more[with\_count($table)](#with-count)$crud-&gt;with\_count('products')Returns only the count of records[has\_count($table)](#has-count)$crud-&gt;has\_count('products')Returns only the records that has count[Advance Add Functionalities](#advance-add-functionalities)

FunctionCodeDescription[push($record)](#push)$crud-&gt;push(record)Adds or updates record if existing[attach($table, $records)](#attach)$crud-&gt;attach('products', \[1,2,3\])Attach records[attach\_new($table, $records, $new)](#attach-new)$crud-&gt;attach\_new('products', $records)Attach new records[detach($table, $records)](#detach)$crud-&gt;detach('products', \[1,2,3\])Detach records[sync($table, $records)](#sync)$crud-&gt;sync('products', $records)Attaches records and detaches the old ones[sync\_new($table, $records)](#sync-new)$crud-&gt;sync\_new('products', $records)Attaches new records and detaches the old ones[save()](#save)$crud-&gt;save()Executes above functions[Helpful Functions](#helpful-functions)

FunctionCodeDescription[get\_result\_count()](#get-result-count)$crud-&gt;get\_result\_count()Get result count[get\_db\_table\_case()](#get-db-table-case)$crud-&gt;get\_db\_table\_case()Get database table case[get\_db\_column\_case()](#get-db-column-case)$crud-&gt;get\_db\_column\_case()Get database column case[change\_case($str, $case)](#change-case)$crud-&gt;change\_case('Your Text', 'pascal')Change text case[recursive\_change\_array\_case($arr, $case)](#recursive-change-array-case)$crud-&gt;recursive\_change\_array\_case()Change array case[recursive\_change\_array\_keys\_case($assoc, $case)](#recursive-change-array-keys-case)$crud-&gt;recursive\_change\_array\_keys\_caseChange array keys case[flatten\_json($json, $case)](#flatten-json)$crud-&gt;flatten\_json($json, 'pascal')Flatten json[validate($validate, $validations)](#validate)$crud-&gt;validate($records, $validations)Use built-in validation[get\_validation\_errors()](#get-validation-errors)$crud-&gt;get\_validation\_errors()Get validation errorsTable of Contents
=================

[](#table-of-contents)

- [What is MySql CRUD](#what-is-mysql-crud)
- [Easy Peasy Summary](#easy-peasy-summary)
- [Installation](#installation)
    - [Install via Composer](#install-via-composer)
    - [Manual installation](#manual-installation)
    - [PHP Users](#php-users)
    - [Codeigniter Users](#codeigniter-users)
    - [Laravel Users](#laravel-users)
    - [Other PHP Frameworks](#other-php-frameworks)-[Basic Functionalities](#basic-functionalities)-[Query Builder](#query-builder)-[Advance Get Functionalities](#advance-get-functionalities)-[Advance Get Related Functionalities](#advance-get-related-functionalities)-[Advance Add Functionalities](#advance-add-functionalities)-[Helpful Functions](#helpful-functions)-[Built-in Validation](#built-in-validation)-[Configuration](#configuration)-[Database Table Configuration](#database-table-configuration)

Installation
============

[](#installation)

To install this project, you have two options:

Install via Composer
--------------------

[](#install-via-composer)

To install using Composer, run the following command:

```
composer require mg3lo/mysql-crud

```

Manual Installation
-------------------

[](#manual-installation)

To install manually, follow these steps:

1. Download the [library](https://github.com/markusoft/dev-tools/raw/main/Mg3lo.zip) from [developer tools](https://github.com/markusoft/dev-tools).
2. Unzip the downloaded file to your extensions directory.

### System requirements

[](#system-requirements)

- PHP 7.0 or higher
- MySQL 5.0 or higher

Note: Tested on the following versions but might work on older versions as well.

PHP Users
---------

[](#php-users)

1. Download the sample [installation](https://github.com/markusoft/dev-tools/raw/main/PHP-MySqlCrud%20v%5B1.0.0%5D.zip) or Install via composer

    ```
    composer require mg3lo/mysql-crud
    ```
2. Load the library on php file

    ```
