When using PHP and MySQL, I know there is a nifty function called mysql_escape_string, to escape whatever you might need to put into your SQL. Now we're coverting from MySQL to Oracle. I'm trying to figure out how to create SQL statments with propertlly escaped strings. There doesn't appear to be an oci_escape_string function. I'm using PHP5 and Oracle 10g on RHEL 4. Thanks in advance.

    There is a addslashes(); function that will do that for you. However I don't think you need both " and ' to be escaped. I would just create your own custom one then for Orcale.

    function oracle_escape_string($str)
    {
    [INDENT]return str_replace("\"", "\\\"", $str);[/INDENT] 
    }
    

    or

    function oracle_escape_string($str)
    {
    [INDENT]return str_replace("'", "\'", $str);[/INDENT] 
    }
    

    Of course this is if you wrap your queries with ".

      dhodge wrote:

      There is a addslashes(); function that will do that for you. However I don't think you need both " and ' to be escaped. I would just create your own custom one then for Orcale.

      Thanks.

      The single quote needs to be escaped. It appears to need to be escaped by putting another single quote in front of it. So I don't think addslashes really is going to help here. I have done as suggested and written my own function to do this. Now of course I have to wonder what other characters need to be escaped.

      I'm also marking this thread as resolved, although I'm not very excited with the solution.

        Write a Reply...