The Jetea Database component.
The following database vendors are currently supported:
- MySQL
- PostgreSQL
composer require jetea/database=~2.0 -vvv
- MySql
$dsn = sprintf('mysql:host=%s;port=%s;dbname=%s;charset=%s', '127.0.0.1', 3306, 'es_demo', 'utf8mb4');
$conn = new MySqlConnection($dsn, 'root', 123123);
- Postgres
$dsn = sprintf('pgsql:host=%s;port=%s;dbname=%s', '127.0.0.1', 3306, 'es_demo');
$conn = new PostgresConnection($dsn, 'root', 123123);
$insertId = $conn->table('profile')->insertGetId([
'name' => 'test-name',
'gender' => 1,
'birthday' => '1988-12-01 01:00:01', //DATETIME
'memo' => 'this is a test memo',
'lat' => '30.54916000', //DECIMAL(10,8)
'lng' => '104.06761000' //DECIMAL(11,8)
]);
$affectNum = $conn->table('profile')->insert([
[
'name' => 'test-name',
'gender' => 1,
'birthday' => '1988-12-01 01:00:01',
'memo' => 'this is a test memo',
'lat' => '30.54916000',
'lng' => '104.06761000'
],
[
'name' => 'test-name-1',
'gender' => 1,
'birthday' => '2010-12-01 01:00:01',
'memo' => 'this is another test memo',
'lat' => '30.54916000',
'lng' => '104.06761000'
],
]);
affectNum = $conn->update('update profile set name = :name, memo = :memo where id = :id', [
':name' => 'test-name',
':memo' => 'this is another memo',
':id' => $id,
]);
$records = $conn->select('select * from profile where id = :id', [
':id' => $id,
]);
$affectNum = $conn->delete('delete from profile where id = :id', [
':id' => $id,
]);
$conn->transaction(function ($conn) {
//do something...
});
$queryLogs = $conn->getQueryLog();
$conn->pretend(function ($conn) {
//do something...
});