gcdb::_real_escape()

最后更新于:2021-11-26 09:06:54

gcdb::_real_escape( string$string)

Real escape, using mysqli_real_escape_string() or mysql_real_escape_string().

参数

$string

(string) (Required) String to escape.

响应

(string) Escaped string.

源文件

文件: gc-includes/gc-db.php

	function _real_escape( $string ) {
		if ( ! is_scalar( $string ) && ! is_null( $string ) ) {
			return '';
		}

		if ( $this->dbh ) {
			if ( $this->use_mysqli ) {
				$escaped = mysqli_real_escape_string( $this->dbh, $string );
			} else {
				$escaped = mysql_real_escape_string( $string, $this->dbh );
			}
		} else {
			$class = get_class( $this );
			if ( function_exists( '__' ) ) {
				/* translators: %s: Database access abstraction class, usually gcdb or a class extending gcdb. */
				_doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), '3.6.0' );
			} else {
				_doing_it_wrong( $class, sprintf( '%s must set a database connection for use with escaping.', $class ), '3.6.0' );
			}
			$escaped = addslashes( $string );
		}

		return $this->add_placeholder_escape( $escaped );
	}