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->escapeIdentifier(string $string): string|false
The identifier (table, column or other name) to escape.
Returns the escaped identifier including the surrounding double quotes, or false on failure, check the error property.
Escape a string for use as a SQL identifier such as a table or column name, using PQescapeIdentifier(). The returned value includes the double quotes.
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=***");
$table = $pg->escapeIdentifier('user data');
var_dump($table); // string(11) ""user data""
$stmt = $pg->query("SELECT * FROM {$table}");
var_dump($stmt->fetchAll());
});