Giter VIP home page Giter VIP logo

landadb's Introduction

Landa DB

Simple Mysql PDO CRUD library

Installation

Install with Composer

Add cahkampung/landa-db to require in composer.json

"require": { "cahkampung/landa-db": "^1.2" },

Run composer install

How To Use

Connection

$config = [
  'DB_DRIVER'      => 'mysql',
  'DB_HOST'        => 'localhost',
  'DB_USER'        => 'root',
  'DB_PASS'        => 'password',
  'DB_NAME'        => 'database',
  'CREATED_USER'   => 'created_by',
  'CREATED_TIME'   => 'created_at',
  'CREATED_TYPE'   => 'int',
  'MODIFIED_USER'  => 'modified_by',
  'MODIFIED_TIME'  => 'modified_at',
  'MODIFIED_TYPE'  => 'int',
  'DISPLAY_ERRORS' => false,
  'USER_ID'        => $_SESSION['user']['id'],
];

$db = new Cahkampung\Landadb($config);

Insert

$db->insert(TABLE_NAME, DATA);

Example :

$data = [
  'name' => 'john',
  'email' => '[email protected]'
];

$db->insert('user_table', $data);

Update

$db->update(TABLE_NAME, DATA, PARAMS);

Example :

$data = [
  'name' => 'john',
  'email' => '[email protected]'
];

$db->update('user_table', $data, ['id' => 1]);

Delete

$db->delete(TABLE_NAME, PARAMS);

Example :

$db->delete('user_table', ['id' => 1]);

Select

select()

select(FIELDS)

FIELDS can be array format, default value is *

from()

from(TABLE)

where()

where(FIELD_NAME, FILTER, VALUE)

andWhere()

andWhere(FIELD_NAME, FILTER, VALUE)

orWhere()

andWhere(FIELD_NAME, FILTER, VALUE)

customWhere()

customWhere(WHERE_STRING, FILTER)

Default filter is And

Example :

customWhere('name = "john" or nationallity = "indonesia"', 'AND');

Will generate AND (name="john" or nationallity="indonesia");

join()

join(JOIN TYPE, TABLE, ONCLAUSE)

leftJoin()

leftJoin(TABLE, ONCLAUSE)

rightJoin()

rightJoin(TABLE, ONCLAUSE)

innerJoin()

innerJoin(TABLE, ONCLAUSE)

limit()

limit(INT)

offset()

offset(INT)

orderBy()

orderBy(FIELD)

groupBy

groupBy(FIELD)

findAll()

Fetch all result from query

Example :

$db->findAll('select * from user_table where name like "%john%" order by name ASC limit 10 offset 0');

Or

$db->select()
    ->from('user_table')
    ->where('name','LIKE','john')
    ->limit(10)
    ->offset(0)
    ->orderBy('name ASC')
$getUsers = $db->findAll();

find()

Fetch 1 results from query

Example :

$db->find('select * from user_table where name like "%john%" order by name ASC');

Or

$db = new Cahkampung\Landadb;
$db->select()
    ->from('user_table')
    ->where('name','LIKE','john')
    ->orderBy('name ASC')
$getUsers = $db->find();

landadb's People

Contributors

wahyuagung26 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.