Thursday, October 17, 2013

Directory Separators Ignored on Inserting into mySQL

Hi, I faced a problem while inserting the file path to mysql database. You can also encounter similar problem when you work with Mysql. So thought of adding this info for your information.

While inserting a file path to my mysql table, I noticed that the slashes in the path are missed once they added to mysql table. This is because the problem is with the backslashes \ , which are often used to escape certain characters. Hence Mysql considers it as a escape character and ignores it.

You can overcome this problem by different methods.

1. You can add double slashes instead of single slash in the directory path.
     Eg: D:\Projects\Test\SQLBackup
           Instead of writing the above path we can write correctly as below:
2. You can just do  quotemeta($rawpath) before the insert statement. This also works.

3. You can also just do addslashes($url).

All the above should work. I just tried the first two and they work perfectly fine. 

So thought of sharing this info with you all. Happy Coding!!!

No comments: