Select from table where name Like (single quote?)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Select from table where name Like (single quote?)

Post by GeXus »

I'm trying to do a selection on all files from a paticular column that contain a single quote... does anyone know how I would do this? by putting the single quote in the query, it always breaks..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your query please.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Quotes are special characters in SQL - they should be escaped using either \' or in some DBMS (and MySQL later versions) '' - 2 single quotes.

So

My dog's name is Rover.

becomes in SQL

'My dog''s name is Rover.' or 'My dog\'s name is Rover' (strings are surrounded by quotes). Read the manual for your database version and type for the correct escaping method to use. MySQL generally accepts the second in most cases - even for MySQL5 I think.
Post Reply