Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ColdFusion, MySQL, single quotes

10 views
Skip to first unread message

Michael Casey

unread,
Feb 10, 2017, 5:34:32 AM2/10/17
to
I am using ColdFusion 11 and a MySQL5 database, with everything set to UTF-8 character encoding. I am having trouble making my selects work properly when they contain single quotes. Here is a simple example:

I have a simple piece of sql:
select * from table where column = 'I've got a single quote';

In my sql client I need to modify this to escape the single quote, thus:
select * from table where column = 'I''ve got a single quote';
And this works correctly.

And in ColdFusion, the query looks like this:
<cfquery name="qryName" datasource="dsn">
select * from table where column = <cfqueryparam CFSQLType="CF_SQL_VARCHAR" value="I've got a single quote" />
</cfquery>
However, the row is not returned and there is no error.

I tried using preserveSingleQuotes too, but still nothing is returned:
<cfqueryparam CFSQLType="CF_SQL_VARCHAR" value="#preserveSingleQuotes(I've got a single quote)#" />

Can anyone suggest what's wrong?
0 new messages