Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-26.11.1 | composer require openswoole/core:26.11.1
<?php OpenSwoole\Coroutine\PostgreSQL->escapeLiteral(string $string): string|false
The string to escape as a SQL string literal.
Returns the escaped literal including the surrounding single quotes, or false on failure, check the error property.
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.
<?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());
});