PHP code example of texlab / mydb
1. Go to this page and download the library: Download texlab/mydb library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
texlab / mydb example snippets
exLab\MyDB\DbEntity;
use TexLab\MyDB\DB;
$link = DB::link([
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'mydb'
]);
$table1 = new DbEntity('table1', $link);
echo json_encode($table1->get());
$table1->add([
'name' => 'Peter',
'description' => 'Director'
]);
$table1->get();
$table1->get(['id' => 3]);
$table1->edit(['id' => 2], [
'name' => 'Alex',
'description' => 'Manager'
]);
$table1->del(['id' => 1]);
echo json_encode($table1->runSQL("SELECT * FROM table1"));
echo json_encode(
$table1
->reset()
->setSelect('id, name')
->setWhere("name like 'A%'")
->get()
);
$table1
->reset()
->setSelect('name, description')
->setWhere("description = 'Manager'")
->setOrderBy('name');
echo json_encode(
$table1->get()
);
$table1->setSelect('*');
echo json_encode(
$table1->get()
);
exLab\MyDB\DB;
use TexLab\MyDB\Runner;
$runner = new Runner(
DB::link(
[
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'dbname' => 'test_db'
]
)
);
$runner->setErrorHandler(
function ($mysqli, $sql) {
//put your error handling code here
print_r([$mysqli->error, $mysqli->errno, $sql]);
}
);
$runner->runSQL("SELECT * FROM unknown_table");
echo $table1
->setPageSize(2)
->pageCount();
echo json_encode($table1->setPageSize(2)->getPage(1));