PHP code example of ikitiki / pgdb

1. Go to this page and download the library: Download ikitiki/pgdb 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/ */

    

ikitiki / pgdb example snippets


$db = new Ikitiki\DB();

$db->setHost('127.0.0.1');
$db->setUsername('postgres');
$db->setDbName('test');

$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'
// ];

$res = $db->exec("select id, name from users")->fetchArray('id', 'name');
// $res = [
//   1 => 'John Doe',
//   2 => 'Richard Roe',
//   3 => 'Mark Moe',
//   ...
// ]

$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]
//   ...
// ];