Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mkabilov/pgdb
PHP Class for working with PostgreSQL database
https://github.com/mkabilov/pgdb
Last synced: 12 days ago
JSON representation
PHP Class for working with PostgreSQL database
- Host: GitHub
- URL: https://github.com/mkabilov/pgdb
- Owner: mkabilov
- License: mit
- Created: 2015-04-18T17:50:58.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-06T18:29:41.000Z (over 8 years ago)
- Last Synced: 2024-04-30T09:21:39.229Z (8 months ago)
- Language: PHP
- Homepage:
- Size: 32.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pgdb
[![Travis](https://travis-ci.org/ikitiki/pgdb.svg?branch=master)](https://travis-ci.org/ikitiki/pgdb)
Class for working with PostgreSQL database
##Usage
Create db instance:
```php
$db = new Ikitiki\DB();$db->setHost('127.0.0.1');
$db->setUsername('postgres');
$db->setDbName('test');
```###Make queries:
Single row query:
```php
$res = $db->execOne(
"select id, name from users where email = '%s' and status_id = %d limit 1",
Ikitiki\DB::quote('[email protected]'),
1
);
// Executes "select id, email from users where email = '[email protected]' and status_id = 1"
// $res = [
// 'id' => 1,
// 'name' => 'John Doe'
// ];
```Key-value queries:
```php
$res = $db->exec("select id, name from users")->fetchArray('id', 'name');
// $res = [
// 1 => 'John Doe',
// 2 => 'Richard Roe',
// 3 => 'Mark Moe',
// ...
// ]
```
or```php
$res = $db->exec("select id, name, department_id from users")->fetchArray('id');
// $res = [
// 1 => ['name' => 'John Doe', 'department_id' => 1],
// 2 => ['name' => 'Richard Roe', 'department_id' => 1],
// 3 => ['name' => 'Mark Moe', 'department_id' => 2]
// ...
// ];
```###Use complex types:
```php
$res = $db->exec('select \'{"id":1,"name":"John Doe","department":"Sales"}\'::json as j from users')->fetchArray('j');
//$res = [
// 'id' => 1,
// 'name' => 'John Doe',
// 'department' => 'Sales',
//]