Mysql POD library
Simple Mysql PDO CRUD library, (*1)
Install with Composer, (*2)
Add cahkampung/landa-db
to require in composer.json, (*3)
"require": { "cahkampung/landa-db": "^1.2" },
, (*4)
Run composer install
, (*5)
$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);
$db->insert(TABLE_NAME, DATA);
, (*6)
Example :, (*7)
$data = [ 'name' => 'john', 'email' => 'john@example.com' ]; $db->insert('user_table', $data);
$db->update(TABLE_NAME, DATA, PARAMS);
, (*8)
Example :, (*9)
$data = [ 'name' => 'john', 'email' => 'john@example.com' ]; $db->update('user_table', $data, ['id' => 1]);
$db->delete(TABLE_NAME, PARAMS);
, (*10)
Example :, (*11)
$db->delete('user_table', ['id' => 1]);
select(FIELDS)
, (*12)
FIELDS can be array format, default value is *
, (*13)
from(TABLE)
, (*14)
where(FIELD_NAME, FILTER, VALUE)
, (*15)
andWhere(FIELD_NAME, FILTER, VALUE)
, (*16)
andWhere(FIELD_NAME, FILTER, VALUE)
, (*17)
customWhere(WHERE_STRING, FILTER)
, (*18)
Default filter is And
, (*19)
Example :, (*20)
customWhere('name = "john" or nationallity = "indonesia"', 'AND');
, (*21)
Will generate AND (name="john" or nationallity="indonesia");
, (*22)
join(JOIN TYPE, TABLE, ONCLAUSE)
, (*23)
leftJoin(TABLE, ONCLAUSE)
, (*24)
rightJoin(TABLE, ONCLAUSE)
, (*25)
innerJoin(TABLE, ONCLAUSE)
, (*26)
limit(INT)
, (*27)
offset(INT)
, (*28)
orderBy(FIELD)
, (*29)
groupBy(FIELD)
, (*30)
Fetch all result from query, (*31)
Example :, (*32)
$db->findAll('select * from user_table where name like "%john%" order by name ASC limit 10 offset 0');
Or, (*33)
$db->select() ->from('user_table') ->where('name','LIKE','john') ->limit(10) ->offset(0) ->orderBy('name ASC') $getUsers = $db->findAll();
Fetch 1 results from query, (*34)
Example :, (*35)
$db->find('select * from user_table where name like "%john%" order by name ASC');
Or, (*36)
$db = new Cahkampung\Landadb; $db->select() ->from('user_table') ->where('name','LIKE','john') ->orderBy('name ASC') $getUsers = $db->find();