Jump to content

string replace (mysql_real_escape_string)


myspacee
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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