To escape ' quotes for MySQL database, we use mysql_real_escape_string.
What if i wish to do it for Oracle database in PHP ?
Solutions that I found:
''(double quotes)q[$string]
To escape ' quotes for MySQL database, we use mysql_real_escape_string.
What if i wish to do it for Oracle database in PHP ?
Solutions that I found:
'' (double quotes)q[$string]Solution 1 sounds wrong (maybe you think right, but wrote wrong); it is not double quotes ", but two consecutive single quotes ''.
Here's an example:
SQL> select
2 'I''m Little O''Foot' option_1,
3 q'[I'm Little O'Foot]' option_2
4 from dual;
OPTION_1 OPTION_2
----------------- -----------------
I'm Little O'Foot I'm Little O'Foot
SQL>
Whichever option you choose, it'll work. The second one is easier to handle because you might get lost when there are way too many single quotes in a string.
Yet another, 3rd option, is to concatenate CHR(39) (which is a single quote character); it can be useful in tools which don't support the q-quoting mechanism (such as old Forms Builders):
SQL> select
2 'I' || chr(39) || 'm Little O' || chr(39) || 'Foot' option_3
3 from dual;
OPTION_3
-----------------
I'm Little O'Foot
SQL>