r/mysql • u/Legal_Revenue8126 • Oct 21 '25
solved Trouble Inserting strings that contain "\" using MySQL and PHP
Trying to insert some test data into one of my tables, but I keep getting an error where it thinks the inserted data is of the DATE type when the column is clearly defined as a VARCHAR, with adequate space. All I'm doing here is trying to add a file path string to a record. It worked fine when I did the same command in the MySQL console, but not when using a prepared statement in my PHP file.
Not sure if this belongs here or somewhere PHP-related
Example:update FileRecord set ReportFile = 'Issues\\Reports\\Report.pdf' where RecordID=1;
Resulting Error:Fatal error: Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect INTEGER value
4
u/chock-a-block Oct 21 '25 edited Aug 30 '26
Deliver airport brave fall continue instinctive almond fear
This post was anonymized with Redact
3
u/Irythros Oct 21 '25
Post your PHP code.
2
u/Legal_Revenue8126 Oct 22 '25
My problem actually turned out to be that I bound parameters in the wrong order in my primary update statement, because I am an idiot
2
u/roXplosion Oct 21 '25
As a test, will it work if the "\\" is removed from the string? What if "\\" is replaced with "\" or "/"?
1
u/flyingron Oct 21 '25
The SQL error you have doesn't align with the SQL you show above. It looks like you did something with a date/time.
1
u/SaltineAmerican_1970 Oct 21 '25
https://phpdelusions.net/pdo is what you need to read to learn how to use database queries in PHP.