File Name in the WHERE clause of Mysql returns nothing
I have the this SELECT query that returns nothing from the spec开发者_如何学运维ified table yet the path to the file is stored in that table;
SELECT * from tableName WHERE imageFile = "C:\Documents and Settings\Albert Bayita\Desktop\MovieImages\TheLordOfTheRingsTheFellowship.jpg";
Any advice is appreciated.
The backslash character is the escape character in strings in MySQL. To put a backslash in a string literal in a query you have to escape it using double backslashes. Also a string in SQL uses apostrophes as delimiter, not quotation marks.
SELECT * from tableName WHERE imageFile = 'C:\\Documents and Settings\\Albert Bayita\\Desktop\\MovieImages\\TheLordOfTheRingsTheFellowship.jpg';
The best option is of course to use a parameterised query instead.
Your table tableName
probably has no imageFile
row with theat exact path.
Parhaps the path is stored differently (perhaps the \ is quoted to \)?
How do you know that is does exist exactly as you have entered in the query?
why you store the whole path in the database
you should figure out something to store just the image name
or if you want to keep on storing the whole path
try
to double the backslash \
SELECT * from tableName WHERE imageFile = "C:\\Documents and Settings\\Albert Bayita\\Desktop\\MovieImages\\TheLordOfTheRingsTheFellowship.jpg";
精彩评论