From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ray O'Donnell <ray@rodonnell.ie>
To: PostgreSQL <pgsql-general@postgresql.org>
Subject: Re: PHP: query with parameter for SET
Date: Tue, 27 Jul 2021 10:15:18 -0700
Message-ID: <7c2c1a89-7cee-1d02-0536-a54b7b1097da@aklaver.com> (raw)
In-Reply-To: <73cf54bb-7bd8-78f2-7997-c4e7d1ac7b0c@rodonnell.ie>
References: <73cf54bb-7bd8-78f2-7997-c4e7d1ac7b0c@rodonnell.ie>
On 7/27/21 10:10 AM, Ray O'Donnell wrote:
> 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.
You probably want set_config():
https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADMIN-SET
9.26.1. Configuration Settings Functions
>
> Thanks,
>
> Ray.
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, ray@rodonnell.ie
Subject: Re: PHP: query with parameter for SET
In-Reply-To: <7c2c1a89-7cee-1d02-0536-a54b7b1097da@aklaver.com>
References: <73cf54bb-7bd8-78f2-7997-c4e7d1ac7b0c@rodonnell.ie> <7c2c1a89-7cee-1d02-0536-a54b7b1097da@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox