OpenSwoole\Coroutine\PostgreSQL->escapeLiteral(...)

Latest version: pecl install openswoole-26.11.1 | composer require openswoole/core:26.11.1

Declaration

<?php OpenSwoole\Coroutine\PostgreSQL->escapeLiteral(string $string): string|false

Parameters

string

The string to escape as a SQL string literal.

Return

Returns the escaped literal including the surrounding single quotes, or false on failure, check the error property.


Description

Escape a string as a complete SQL string literal using PQescapeLiteral(). Unlike escape(), the returned value already includes the single quotes, so do not quote it again.

The client must be connected.


Example

<?php

use OpenSwoole\Coroutine\PostgreSQL;

co::run(function()
{
    $pg = new PostgreSQL();
    $pg->connect("host=127.0.0.1 port=5432 dbname=test user=postgres password=***");

    $name = $pg->escapeLiteral("O'Reilly");
    var_dump($name); // string(11) "'O''Reilly'"

    $stmt = $pg->query("SELECT * FROM users WHERE name = {$name}");
    var_dump($stmt->fetchAll());
});
Last updated on November 20, 2026