mirror of
https://github.com/danog/postgres.git
synced 2024-11-30 04:29:12 +01:00
Error if pecl-ev is used with ext-pgsql
This commit is contained in:
parent
650d464ef8
commit
616da4ac4e
@ -24,8 +24,12 @@ composer require amphp/postgres
|
||||
- PHP 7.0+
|
||||
- [ext-pgsql](https://secure.php.net/pgsql) or [pecl-pq](https://pecl.php.net/package/pq)
|
||||
|
||||
Note: [pecl-ev](https://pecl.php.net/package/ev) is not compatible with ext-pgsql. If you wish to use pecl-ev for the event loop backend, you must use pecl-pq.
|
||||
|
||||
## Documentation & Examples
|
||||
|
||||
Prepared statements and parameterized queries support named placeholders, as well as `?` and standard numeric (i.e. `$1`) placeholders.
|
||||
|
||||
More examples can be found in the [`examples`](examples) directory.
|
||||
|
||||
```php
|
||||
@ -34,10 +38,10 @@ Amp\Loop::run(function () {
|
||||
$pool = Amp\Postgres\pool("host=localhost user=postgres dbname=test");
|
||||
|
||||
/** @var \Amp\Postgres\Statement $statement */
|
||||
$statement = yield $pool->prepare("SELECT * FROM test WHERE id=$1");
|
||||
$statement = yield $pool->prepare("SELECT * FROM test WHERE id = :id");
|
||||
|
||||
/** @var \Amp\Postgres\ResultSet $result */
|
||||
$result = yield $statement->execute([1337]);
|
||||
$result = yield $statement->execute(['id' => 1337]);
|
||||
while (yield $result->advance()) {
|
||||
$row = $result->getCurrent();
|
||||
// $row is an array (map) of column values. e.g.: $row['column_name']
|
||||
|
@ -15,8 +15,15 @@ class PgSqlConnection extends Connection {
|
||||
* @param \Amp\CancellationToken $token
|
||||
*
|
||||
* @return \Amp\Promise<\Amp\Postgres\PgSqlConnection>
|
||||
*
|
||||
* @throws \Error If pecl-ev is used as a loop extension.
|
||||
*/
|
||||
public static function connect(string $connectionString, CancellationToken $token = null): Promise {
|
||||
// @codeCoverageIgnoreStart
|
||||
if (Loop::get()->getHandle() instanceof \EvLoop) {
|
||||
throw new \Error('ext-pgsql is not compatible with pecl-ev; use pecl-pq or a different loop extension');
|
||||
} // @codeCoverageIgnoreEnd
|
||||
|
||||
$connectionString = \str_replace(";", " ", $connectionString);
|
||||
|
||||
if (!$connection = @\pg_connect($connectionString, \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW)) {
|
||||
|
Loading…
Reference in New Issue
Block a user