encodeForSQL

Encodes a string for use in a SQL statement.

encodeForSQL(string, dialect [, canonicalize]) → returns string

This function requires Lucee 5 and up.  Not supported on Adobe ColdFusion, etc.

Discouraged: Escaping is easy to get wrong and can still leave a query open to SQL injection. Use cfqueryparam or queryExecute() parameters instead.

Argument Reference

string string
Required

The string to encode.

dialect string
Required

The SQL dialect: db2, mysql_ansi, mysql or oracle.

canonicalize boolean
Default: false

When true, the string is canonicalized before it is encoded.

Examples
Sample code invoking the encodeForSQL function

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub