Jump to content

Recommended Posts

Posted

Hello,

i use Autoit for insert informations into mysql db

Before that i use PHP but not fast as AI for Insert. Try to replicate a PHP function to text: mysql_real_escape_string

this PHP function is a stringreplace for these cases :

  • x00
  • n
  • r
  • '
  • "
  • x1a

 

anyone can post correct way to implement these text substitutions ?

Thank you!

m.

Posted

thank you mikell,

i hate compile StringRegExpReplace, I'm always afraid of making mistakes...

why you set "replace"= '$1'  ?

(StringRegExpReplace ( "test", "pattern", "replace", [count] )) ?

thank you again,

m.

 

Posted

Thank you for support,

so PHP function is not a simple text replacer, but it add escaping chars to given string...

so to emulate PHP function this is bad :

$str2 = StringRegExpReplace($str, '([\x00\\"\x1a\r\n''])', '')

and this is right way ?

$str2 = StringRegExpReplace($str, '([\x00\\"\x1a\r\n''])', '\\$1')

I'm sorry, but i need an additional clarification; i'm replacing an old PHP script with a custom tool,

and i must be sure to do it in best way possible.

thank you again for your time,

m.

Posted

I'm not familiar with mysql but googling "mysql_real_escape_string alternative" I got this :

function mres($value)
{
    $search = array("\\",  "\x00", "\n",  "\r",  "'",  '"', "\x1a");
    $replace = array("\\\\","\\0","\\n", "\\r", "\'", '\"', "\\Z");

    return str_replace($search, $replace, $value);
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...