Your error apparently clearly states what the problem is:
ERROR: invalid input syntax for type timestamp: ""
It looks like your query is trying to insert an empty string into a PostgreSQL field that is of type "timestamp". If you insert an invalid string of any type, it should appear in the error you receive:
ERROR: invalid input syntax for type timestamp: "foobardtimestamp"
Or, in your case, if your expected string was passed, your error might look like this:
ERROR: invalid input syntax for type timestamp: "2002-03-11"
... but the error does not say what makes me suspect that your string is not actually passed to the request, as you think. The fact is that, as stated earlier, PostgreSQL should perfectly handle 2002-03-11 as a valid timestamp string.
PostgreSQL does not like to insert '' (empty string) as a timestamp and will complain about the error you provided.
If you want to provide an empty row, you must be sure that you do not have a NOT NULL restriction on the column, and you need to use null instead of the empty row. If you don't want to send an empty string, I would check the value of $pdo->quote($date) to make sure you get the string you want to return.
You can also try to dump the generated SQL before you run the query to make sure it looks right. I have a feeling if you do this, it will look something like this:
INSERT INTO dates(date) VALUES('')
Also, for what it's worth, your example says you're working: $pdo->query($date); when I'm sure you want: $pdo->query($query);
ilovebonnie.net
source share