RE: [PHP-DB] Postgres query failing, not enough info for debugging...

From: Date: Wed, 17 Jun 2009 10:39:28 +0000
Subject: RE: [PHP-DB] Postgres query failing, not enough info for debugging...
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-46236@lists.php.net to get a copy of this message
On 16 June 2009 15:57, Carol Walter advised: > Hello, > > I'm using PHP 5 and PostgreSQL 8.3.6. I have a query that is failing > and I don't know how to troubleshoot the problem. The error message > that it is giving is quite vague. The error message is as follows: > > > Warning: pg_query_params() [function.pg-query-params]: Query failed: > ERROR: syntax error at end of input at character 156 in /home/walterc/ > ssl/PHP/km_input_test2c.php on line 631 > ERROR: syntax error at end of input at character 156 > > The query that is failing looks like this... > > $pg_pres_ins6 = pg_query_params("INSERT INTO \"brdgMediaCallsEvents > \" (\"mediumId\", \"eventId\", rank) VALUES > ((currval('\"tblMedia_mediumId_seq\"'), > (currval('\"tblCallsEvents_eventId_seq\"'), $1)", array($ev_rank)); > echo pg_last_error($pg_connection); You have 2 more opening parentheses than close parentheses in that SQL -- in both cases, the parenthesis immediately preceding currval should be omitted. Also, to ameliorate your quote hell, you might consider using a heredoc (http://php.net/manual/language.types.string.php#language.types.string.s yntax.heredoc) for this: $pg_pres_ins6 = pg_query_params(<<<SQL INSERT INTO "brdgMediaCallsEvents" ("mediumId", "eventId", rank) VALUES (currval('"tblMedia_mediumId_seq"'), currval('"tblCallsEvents_eventId_seq"'), $1) SQL , array($ev_rank)); Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

« previous php.db (#46236) next »