1. Go to this page and download the library: Download simplon/postgres 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/ */
simplon / postgres example snippets
$dbConn->fetchRow('SELECT * FROM names WHERE name = :name', array('name' => 'Peter'));
$sqlBuilder = new \Simplon\Postgres\Manager\PgSqlQueryBuilder();
$sqlBuilder
->setQuery('SELECT * FROM names WHERE name = :name')
->setConditions(array('name' => 'Peter'));
$pgSqlManager = new \Simplon\Postgres\Manager\PgSqlManager($dbConn);
$pgSqlManager->fetchRow($sqlBuilder);
$pgSqlManager = new \Simplon\Postgres\Manager\PgSqlManager($dbConn);
$result = $dbConn->fetchColumn('SELECT id FROM names WHERE name = :name', array('name' => 'Peter'));
// result
var_dump($result); // '1' || false
$result = $dbConn->fetchColumnMany('SELECT id FROM names WHERE name = :name', array('name' => 'Peter'));
// result
var_dump($result); // ['1', '15', '30', ...] || false
$cursor = $dbConn->fetchColumnMany('SELECT id FROM names WHERE name = :name', array('name' => 'Peter'));
foreach ($cursor as $result)
{
var_dump($result); // '1'
}
$result = $dbConn->fetchRow('SELECT id, age FROM names WHERE name = :name', array('name' => 'Peter'));
var_dump($result); // ['id' => '1', 'age' => '22'] || false
$result = $dbConn->fetchRowMany('SELECT id, age FROM names WHERE name = :name', array('name' => 'Peter'));
var_dump($result); // [ ['id' => '1', 'age' => '22'], ['id' => '15', 'age' => '40'], ... ] || false
$result = $dbConn->fetchRowMany('SELECT id, age FROM names WHERE name = :name', array('name' => 'Peter'));
foreach ($cursor as $result)
{
var_dump($result); // ['id' => '1', 'age' => '22']
}
$sqlBuilder = new \Simplon\Postgres\Manager\PgSqlQueryBuilder();
$sqlBuilder
->setQuery('SELECT id FROM names WHERE name = :name')
->setConditions(array('name' => 'Peter'));
$result = $pgSqlManager->fetchColumn($sqlBuilder);
// result
var_dump($result); // '1' || false
$sqlBuilder = new \Simplon\Postgres\Manager\PgSqlQueryBuilder();
$sqlBuilder
->setQuery('SELECT id FROM names WHERE name = :name')
->setConditions(array('name' => 'Peter'));
$result = $pgSqlManager->fetchColumnMany($sqlBuilder);
// result
var_dump($result); // ['1', '15', '30', ...] || false
$sqlBuilder = new \Simplon\Postgres\Manager\PgSqlQueryBuilder();
$sqlBuilder
->setQuery('SELECT id FROM names WHERE name = :name')
->setConditions(array('name' => 'Peter'));
foreach ($pgSqlManager->fetchColumnMany($sqlBuilder) as $result)
{
var_dump($result); // '1'
}
$sqlBuilder = new \Simplon\Postgres\Manager\PgSqlQueryBuilder();
$sqlBuilder
->setQuery('SELECT id, age FROM names WHERE name = :name')
->setConditions(array('name' => 'Peter'));
$result = $pgSqlManager->fetchRow($sqlBuilder);
var_dump($result); // ['id' => '1', 'age' => '22'] || false
$sqlBuilder = new \Simplon\Postgres\Manager\PgSqlQueryBuilder();
$sqlBuilder
->setQuery('SELECT id, age FROM names WHERE name = :name')
->setConditions(array('name' => 'Peter'));
$result = $pgSqlManager->fetchRowMany($sqlBuilder);
var_dump($result); // [ ['id' => '1', 'age' => '22'], ['id' => '15', 'age' => '40'], ... ] || false
$sqlBuilder = new \Simplon\Postgres\Manager\PgSqlQueryBuilder();
$sqlBuilder
->setQuery('SELECT id, age FROM names WHERE name = :name')
->setConditions(array('name' => 'Peter'));
foreach ($pgSqlManager->fetchRowManyCursor($sqlBuilder) as $result)
{
var_dump($result); // ['id' => '1', 'age' => '22']
}
// conditions: where id = 1
$conds = array('id' => 1);
/** @var UserVo $userVo */
$userVo = $PgSqlCrudManager->read(new UserVo(), $conds);
// print name
echo $userVo->getName(); // Johnny Foobar
// conditions: where id = 1
$conds = array('id' => 1);
/** @var UserVo $userVo */
$userVo = $PgSqlCrudManager->read(new UserVo(), $conds);
// set new name
$userVo->setName('Hansi Hinterseher');
// update
/** @var UserVo $userVo */
$userVo = $PgSqlCrudManager->update($userVo, $conds);
// print name
echo $userVo->getName(); // Hansi Hinterseher
// conditions: where id = 1
$conds = array('id' => 1);
/**
* UserVo::crudGetSource() is the name of the table
* based on the value object's name
*/
$PgSqlCrudManager->update(UserVo::crudGetSource(), $conds);
class PersonVo extends \Simplon\Postgres\Crud\PgSqlCrudVo
{
/**
* @return string
*/
public static function crudGetSource()
{
return 'people';
}
// ... here goes the rest
}
class UserVo extends \Simplon\Postgres\Crud\PgSqlCrudVo
{
protected $id;
protected $name;
protected $email;
protected $createdAt;
protected $updatedAt;
/**
* @return array
*/
public function crudColumns()
{
return array(
'id' => 'xx_id',
'name' => 'xx_name',
'email' => 'xx_email',
'createdAt' => 'xx_created_at',
'updatedAt' => 'xx_updated_at',
);
}
// ... here goes the rest
}
class UserVo extends \Simplon\Postgres\Crud\PgSqlCrudVo
{
protected $id;
protected $name;
protected $email;
protected $createdAt;
protected $updatedAt;
// helper property: not part of the people table
protected $isOffline;
/**
* @return array
*/
public function crudIgnore()
{
return array(
'isOffline',
);
}
// ... here goes the rest
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.