restu / dbhelper
package library for help you to use database
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2025-06-11 23:13:54 UTC
README
Halo, mohon untuk di coba dbhelper php yang saya buat, semoga bisa membantu dalam kode kamu.
~Terima Kasih
Cara Pakai
Lihat Index.php untuk implementasi
1. Install & Config
1.1 copy or clone dbhelper ke app kamu.
//if use composer composer require restu/dbhelper
1.2 config koneksi database di folder /config file db.json.
di folder /dbhelper/config file db.json.
2. Buat Table Class
buat table class sesuai database / tabel kamu didalam folder /dbhelper/dbclass
//table class must use namespace dbhelper & extends from _tbl namespace dbhelper; class Tbl extends _tbl{ protected $_tbl = 'tbl'; protected $_pk = 'id'; //must have primary key //define fields protected $_fields = [ 'id' => null ,'namatest' => null ,"info" => null ]; }
3. required _dbloader.php or autoload vendor composer
require _dbloader.php atau autoload vendor composer di atas dokumen php kamu agar bantuan database / tabel bisa di panggil
require ("dbhelper/_dbloader.php"); //if use composer require_once __DIR__ . '/vendor/autoload.php'; //your folder app need this -- Your App Folder --- dbhelper --config --db.json //your connection to database --dbclass --Tbl.php //your tbl class
4. Intansiasi Tabel
Instansiasi tabel yang diperlukan dengan new dbhelper\Tbl()
//with new dbhelper\; $tbl = new dbhelper\Tbl();
5. Good luck & Have fun with your app
5.1 Create
5.1.1 Insert 1
$tbl->insert(associativeArray)
$argsInsert = [ "namatest" => "nilai" ,"info" => "nilai record yang di insert" ]; $tbl -> insert($argsInsert);
5.1.2 Insert 2
one by one set value field then call $tbl -> new();
$tbl -> setValue("namatest", "nilai" ); //field name, value record $tbl -> setValue("info", "nilai record yang di insert"); $tbl -> new();
5.2 Update
5.2.1 Update 1
by primary keys value
$argsUpdate = [ "namatest" => "nilai Update" ,"info" => "nilai record yang di update edit" ]; $tbl -> update('1',$argsUpdate);
5.2.2 Update 2
by filter
$argsWhereFilter = [ "namatest" => "nilai Update" ]; $argsUpdate = [ "namatest" => "nilai Update" ,"info" => "nilai record yang di update edit" ]; $tbl -> updateBy($argsWhereFilter,$argsUpdate);
5.3 Delete
5.3.1 Delete 1
by primary keys value
$tbl -> delete('1');
5.3.2 Delete 2
by filter
$argsDeleteFilter = [ "namatest" => "nilaid" ]; $tbl -> deleteBy($argsDeleteFilter);
5.4 Get
Get only get one data and add to fields table
5.4.1 Get 1
get by keys arrays by primary key
$record = $tbl -> get(['5']);
5.4.2 Get 2
if you have other unique value can use getBy
$tbl -> getBy('field','value'); $record = $tbl -> getBy('id','4');
5.5 Query
even you can query many data
$records = $tbl -> query("id,namatest,info",[ "namatest='nilai'" //," and " //,"id = '5'" ]);
6. Other Feature
6.1 Get Next Number
$number = $tbl -> nextno("id"); echo $number; $number = $tbl -> nextno("id", ["namatest='nilaidf'"]); echo $number;
6.2 encrypt & verify value field
$tbl -> encrypt("namatest", "realvalue"); echo $tbl -> value("namatest"); //verify value field will return 1 if verified $isVerify = $tbl -> verify("namatest", "realvalue"); echo $isVerify;
6.3 time
$time = $tbl -> timeNow(); echo $time;
6.4 setvalue & unset field
$tbl->setValue("infodsf",7); $tbl->unset(["infodsf"]); echo $tbl->value("infodsf");