PHP: query with parameter for SET

From: Ray O'Donnell <ray(at)rodonnell(dot)ie>
To: 'PostgreSQL' <pgsql-general(at)postgresql(dot)org>
Subject: PHP: query with parameter for SET
Date: 2021-07-27 17:10:25
Message-ID: 73cf54bb-7bd8-78f2-7997-c4e7d1ac7b0c@rodonnell.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi everyone,

Using PHP (or indeed maybe more generally), is it possible to issue a
SET TIME ZONE statement with a parameter for the new runtime setting?

In a PHP application I'm issuing a SET TIME ZONE command just after the
database connection is created, and for security I'd like to pass the
time zone value in a parameter, as it's coming from a configuration file
- something like this:

$pdo = new PDO(/* DSN goes here */);

$statement = $pdo->prepare('set time zone :tz');
$statement->execute([':tz' => 'Europe/Dublin']);

However, in the logs I see:

ERROR: syntax error at or near "to" at character 15
STATEMENT: set time zone $1

Is this possible? I've also tried the "set timezone ..." variant with
similar results. I'm wondering too if the limitation (if such it is) is
in PHP or whether it's a Postgres thing.

Thanks,

Ray.

--
Raymond O'Donnell // Galway // Ireland
ray(at)rodonnell(dot)ie

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2021-07-27 17:15:18 Re: PHP: query with parameter for SET
Previous Message Marc Millas 2021-07-27 17:07:43 sort order