1. Go to this page and download the library: Download makise-co/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/ */
makise-co / postgres example snippets
declare(strict_types=1);
use MakiseCo\Postgres\ConnectionConfig;
use MakiseCo\Postgres\ConnectionConfigBuilder;
use MakiseCo\Postgres\Driver\Pq\PqConnection;
use MakiseCo\Postgres\Driver\PgSql\PgSqlConnection;
use MakiseCo\Postgres\Driver\Swoole\SwooleConnection;
use MakiseCo\SqlCommon\Contracts\ResultSet;
use function Swoole\Coroutine\run;
run(static function () {
$config = (new ConnectionConfigBuilder())
->withHost('127.0.0.1')
->withPort(5432)
->withUser('makise')
->withPassword('el-psy-congroo')
->withDatabase('cern')
->withSslMode('prefer')
->withEncoding('utf-8')
->withApplicationName('Makise Postgres Driver')
->withSearchPath(['public'])
->withTimezone('UTC')
->withConnectTimeout(1.0) // wait 1 second
->build();
// or:
$config = (new ConnectionConfigBuilder())
->fromArray([
'host' => '127.0.0.1',
'port' => 5432,
'user' => 'makise',
'password' => 'el-psy-congroo',
'database' => 'cern',
'sslmode' => 'prefer',
'client_encoding' => 'utf-8',
// or
'encoding' => 'utf-8',
// or
'charset' => 'utf-8',
'application_name' => 'Makise Postgres Driver',
'search_path' => 'public', // array of strings can be passed
// or
'schema' => 'public', // array of strings can be passed
'timezone' => 'UTC',
'connect_timeout' => 1.0,
])
->build();
// or
$config = new ConnectionConfig(
'127.0.0.1',
5432,
'makise',
'el-psy-congroo',
'makise',
[
'sslmode' => 'prefer',
'client_encoding' => 'utf-8',
'application_name' => 'Makise Postgres Driver',
'options' => [
'search_path' => 'public',
'timezone' => 'UTC',
],
],
1.0,
);
$connection = PqConnection::connect($config);
// or
$connection = PgSqlConnection::connect($config);
// or
$connection = SwooleConnection::connect($config);
$statement = $connection->prepare("SELECT * FROM test WHERE id = :id");
/** @var ResultSet $result */
$result = $statement->execute(['id' => 1337]);
while ($row = $result->fetchAssoc()) {
// $row is an array (map) of column values. e.g.: $row['column_name']
}
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.