swoole_mysql->escape

转义SQL语句中的特殊字符,避免SQL注入攻击。底层基于mysqlnd提供的函数实现,需要依赖PHP的mysqlnd扩展。

此方法在1.9.6或更高版本可用

function swoole_mysql->escape(string $str) : string

使用实例

$db = new swoole_mysql;
$server = array(
    'host' => '127.0.0.1',
    'user' => 'root',
    'password' => 'root',
    'database' => 'test',
);
$db->connect($server, function ($db, $result) {
    $data = $db->escape("abc'efg\r\n");
});