Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql_real_escape_string alternative for SQL Server [duplicate]

Am wondering what is the equivalent in PHP for SQL Server escaping of strings?

like image 324
Alec Smart Avatar asked Jan 27 '10 11:01

Alec Smart


1 Answers

Nice question, I don't know but you could use PDO::quote() with the PDO_DBLIB driver.


EDIT: Seems like this guy got it from StackOverflow:

function mssql_escape($data) {
    if(is_numeric($data))
        return $data;
    $unpacked = unpack('H*hex', $data);
    return '0x' . $unpacked['hex'];
}

Another option:

function mssql_escape($str)
{
    if(get_magic_quotes_gpc())
    {
        $str= stripslashes($str);
    }
    return str_replace("'", "''", $str);
}
like image 59
Alix Axel Avatar answered Sep 19 '22 18:09

Alix Axel