WordPress 常用函数 / esc_sql

$wpdb->_escape() 的别名,用于进行 SQL 查询之前的字符串处理。

<?php esc_sql( $sql ); ?>

$string
(string) (required) 一条转义的 SQL 查询语句。
Default: None

(string)
转义之后适合 SQL 查询中使用的字符串。

$name=esc_sql($name);
$status=esc_sql($status);
$wpdb->get_var( 
  "SELECT something FROM table WHERE foo = '$name' and status = '$status'"
);

SQL 转义还是建议首选 $wpdb->prepare(),因为它可以修正一些格式方面的错误。

Since: 2.8.0

wp-includes/formatting.php