Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m8Qfv-0000Q2-Sm for pgsql-general@arkaria.postgresql.org; Tue, 27 Jul 2021 17:15:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m8Qfu-00029c-Sx for pgsql-general@arkaria.postgresql.org; Tue, 27 Jul 2021 17:15:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m8Qft-00029T-HC for pgsql-general@lists.postgresql.org; Tue, 27 Jul 2021 17:15:26 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m8Qfq-0005ZJ-5x for pgsql-general@postgresql.org; Tue, 27 Jul 2021 17:15:24 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 9F3C53200904; Tue, 27 Jul 2021 13:15:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 27 Jul 2021 13:15:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=T 3LLGssmyuSpQQ1lLll/1ALQqP5pecDiArxsH6aB2FE=; b=n2sEOIQJspO+hlDBO ONlmcq6JDbeG3x+wlTgeLdQIWyD9W/PNI58/iRP7uydZJKSkYqtAyDYBtTkFfKYR SiKBTEUPBOk3RPwqzp4gvZ7rMagmhNEv/nBTLKUigW1Qu6y2Gfpb8QO/GKhK7WRz DIFk0CsAj/BVoEANq7nxVm3I2HplirIV9lmAz/CweR0nLM/dDXM3gZ5extBbwWU2 8iq4bf7DQ4jEyr4DWUSV/hKMy7sPMNb16dc4TizQZrhmip2UyEYc2Cdg4ptt0Ilg M9jmFjLohMmWNeJ1GFOid4v5KwYAlDvFIY9y+TM7Sl4cKBGNyn64JRbhB3vn/yGS rdZ+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=T3LLGssmyuSpQQ1lLll/1ALQqP5pecDiArxsH6aB2 FE=; b=WNkfaVwbo9Pd9Jxq8b52UD7q8hMPpq2Ebe1qifkvlYDRpRYTn8qgrUkho f5Yfq+3WtTPyQVbnIiqUG7Aw8MjTVAkp50fkicm4j2hdub91w0RjyMpaW5dMCUAT IQJcIZE/ThUu7q64nw+qla9bQZX4xoGlg5R1mwJPut/Bxkfwt4qxaSYGUZG6bW4m w2DinPcLTxsXdCKBRcG/nBwjgje70FbyCCzQbymZg6qP7fXLdHx7e8scqNK4zKgG U1YEO0FWsfoYMFHK8s1EaAwna1h/CKUwKrv4edKXEw1BCSR9IH8sorxNgw+alCxo VSE3KUtyPLUSPaQPfx9xR7ZeDsT6Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrgeejgddutdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepuddufeejte evffehgfduhedthfdvteekieeuheefveevudetkeelueehgeduhefhnecuffhomhgrihhn pehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgt ohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 27 Jul 2021 13:15:19 -0400 (EDT) Subject: Re: PHP: query with parameter for SET To: Ray O'Donnell , 'PostgreSQL' References: <73cf54bb-7bd8-78f2-7997-c4e7d1ac7b0c@rodonnell.ie> From: Adrian Klaver Message-ID: <7c2c1a89-7cee-1d02-0536-a54b7b1097da@aklaver.com> Date: Tue, 27 Jul 2021 10:15:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <73cf54bb-7bd8-78f2-7997-c4e7d1ac7b0c@rodonnell.ie> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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