1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-15 10:57:22 +01:00
postgres/lib/functions.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2016-12-30 06:21:17 +01:00
<?php
2016-09-14 16:27:39 +02:00
namespace Amp\Postgres;
use Amp\Promise;
2016-09-14 16:27:39 +02:00
/**
* @param string $connectionString
* @param int $timeout
*
* @return \Amp\Promise<\Amp\Postgres\Connection>
2016-09-14 16:27:39 +02:00
*
* @throws \Amp\Postgres\FailureException If connecting fails.
* @throws \Error If neither ext-pgsql or pecl-pq is loaded.
*/
function connect(string $connectionString, int $timeout = 0): Promise {
2016-09-14 16:27:39 +02:00
if (\extension_loaded("pq")) {
return PqConnection::connect($connectionString, $timeout);
}
if (\extension_loaded("pgsql")) {
return PgSqlConnection::connect($connectionString, $timeout);
}
2017-04-15 01:33:31 +02:00
throw new \Error("amphp/postgres requires either pecl-pq or ext-pgsql");
2016-09-14 16:27:39 +02:00
}
/**
* @param string $connectionString
* @param int $maxConnections
* @param int $connectTimeout
*
* @return \Amp\Postgres\Pool
*/
function pool(
string $connectionString,
int $maxConnections = ConnectionPool::DEFAULT_MAX_CONNECTIONS,
int $connectTimeout = ConnectionPool::DEFAULT_CONNECT_TIMEOUT
): Pool {
return new ConnectionPool($connectionString, $maxConnections, $connectTimeout);
}