SQL Server 的 mysql_real_escape_string 替代方案 [英] mysql_real_escape_string alternative for SQL Server

查看:155
本文介绍了SQL Server 的 mysql_real_escape_string 替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道 PHP 中 SQL Server 转义字符串的等价物是什么?

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

推荐答案

好问题,我不知道,但你可以使用 PDO::quote()PDO_DBLIB 驱动程序.

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

看起来像 这家伙 从 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);
}

这篇关于SQL Server 的 mysql_real_escape_string 替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆