简体   繁体   中英

PHP PDO SQLite3 converting date string

Using SQLite3, PDO and PHP5 on localhost only.

Am using a webpage table to display the columns, a sample set (1 record from the table), checkboxes for selecting columns, and dropdowns for selecting modifyers for the subsequent query. At the time the "get query" button is clicked, the simple query..

SELECT day FROM tbl;

..gets turned into..

SELECT datetime([day],'unixepoch','+978307200 seconds','localtime') as day FROM tbl;

(This is done via a string replace function)

It's then passed via a cookie to a results page (using cookies because I'm also passing a lot of other data)

This query will now add all those seconds to the converted unix epoch time, and give up a result in localtime...(vs UTC)

If I hardcode the query directly into the "results.php" page, it works fine. If the page uses the query stored in the cookie set by the previous page, I get no results. Inspecting the results page elements, I can see the cookie has been set with the complete query.

I've narrowed it down to the "+978307200" modifyer...because without it, it works fine (apart from being 978307200 seconds out of kilter!)

I'm picking that something is happening to the "+" sign, but at a complete loss as to how to fix it.

Any ideas/suggestions? Thanks.

In URL's and cookies plus sing is a placeholder for space and $_COOKIES array contains parsed cookie headers, so every plus is changed into space there.

If you really must pass this kind of data between pages, use session for it.

If session is not an option for some reason, you will have to encode your values to contain only 'safe' characters before storing them into cookie, and then decode it before using. Most popular for this is base64_ functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM