|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-09-23 15:05 UTC] sjoerd@php.net
[2009-09-23 15:09 UTC] alandsidel at dnsstuff dot com
[2009-09-25 17:19 UTC] sjoerd@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 00:00:02 2025 UTC |
Description: ------------ Running PostGreSQL 8.4, given a simple table like: When using a bound parameter in prepare (named or unnamed) to a timestamp field, the parameter is improperly quoted resulting in errors on INSERT or UPDATE statements that are using expressions rather than simple datetime strings. Reproduce code: --------------- // In the postgresql database CREATE TABLE foo ( id SERIAL UNIQUE NOT NULL, dtSometime TIMESTAMP WITH TIME ZONE NOT NULL ); // Assuming $dbh is a connection to the above database if ($stmt = $dbh->prepare('INSERT INTO foo (dtSometime) VALUES (:dtsometime)') { if ($stmt->execute(array('now() + interval \'1 year\'')) { print("ok!\n"); } else { print_r($dbh->errorInfo()); } } Expected result: ---------------- Expect a row to be inserted and 'ok!' to print. Actual result: -------------- The following is printed on the console: //--cut ( [0] => 00000 [1] => 7 [2] => ERROR: invalid input syntax for type timestamp with time zone: "now() + interval '1 year'" ) //--cut A direct insert with the given SQL works fine as expected, so this must be a quoting issue that is forcing postgresql to interpret the expression as a literal datetime.