sharpedge/cruder

php database connection and crud application made easy

v1.0.6 2021-08-27 07:35 UTC

This package is auto-updated.

Last update: 2024-04-27 14:12:20 UTC


README

Cruder is Simple libaray to perform all your database functions. it is very easy as ABC

It is still under development and the community is welcome to add their functions

using this library, you can perform certain mysql functions like

  • Select
    • Select with limit
    • Select with Offset
    • Select specific columns
  • Insert
    • Insert as an array (forget about queries)

Example of Select

  use Cruder\Sharp\SharpCrud as Cruder;
  $cruder = Cruder::getInstance('localhost', 'root', '', 'employees');
  $cruder->table('employees');
  $result = $cruder->getAll();

Select specific columns

  use Cruder\Sharp\SharpCrud as Cruder;
  $cruder = Cruder::getInstance('localhost', 'root', '', 'employees');
  $select = array('emp_no', 'dept_no');
  $cruder->table('employees');
  $cruder->select($select);
 
  $result = $cruder->getAll();

Select with Limit

  use Cruder\Sharp\SharpCrud as Cruder;
  $cruder = Cruder::getInstance('localhost', 'root', '', 'employees');
  $cruder->table('employees');
  $cruder->limit(50);
  $result = $cruder->getAll();

Select with Limit and offset

  use Cruder\Sharp\SharpCrud as Cruder;
  $cruder = Cruder::getInstance('localhost', 'root', '', 'employees');
  $cruder->table('employees');
  $cruder->offset(1);
  $cruder->limit(50);
  $result = $cruder->getAll();
  • Raw Select query*
  use Cruder\Sharp\SharpCrud as Cruder;
  $cruder = Cruder::getInstance('localhost', 'root', '', 'employees');
  $query = "SELECT * FROM table_name";
  $result = $cruder->raw($query);

Select with WHERE

  use Cruder\Sharp\SharpCrud as Cruder;
  $cruder = Cruder::getInstance('localhost', 'root', '', 'employees');
  //WHERE has to be an array
  $cruder->table('employees')->where(array('emp_no', '=', 500000));
  $result = $cruder->getAll();

Even the insert is very easy:

  use Cruder\Sharp\SharpCrud as Cruder;
  $cruder = Cruder::getInstance('localhost', 'root', '', 'employees');
  $cruder->table('employees');
  $insert = array('emp_no' => '500000', 'birth_date' => '1992-01-21', 'first_name'=> "husnain", "last_name" => 'ahmed', 'gender' => 'M', 'hire_date' => '2001-04-02');
  $insert_return = $cruder->insert($insert); // it will return the inserted ID