- if ( $this->has_cap( 'collation', $dbh ) && !empty( $charset ) ) {
- if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset', $dbh ) ) {
- mysql_set_charset( $charset, $dbh );
- $this->real_escape = true;
+ if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) {
+ if ( $this->use_mysqli ) {
+ if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
+ mysqli_set_charset( $dbh, $charset );
+ } else {
+ $query = $this->prepare( 'SET NAMES %s', $charset );
+ if ( ! empty( $collate ) )
+ $query .= $this->prepare( ' COLLATE %s', $collate );
+ mysqli_query( $query, $dbh );
+ }
+ } else {
+ if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
+ mysql_set_charset( $charset, $dbh );
+ } else {
+ $query = $this->prepare( 'SET NAMES %s', $charset );
+ if ( ! empty( $collate ) )
+ $query .= $this->prepare( ' COLLATE %s', $collate );
+ mysql_query( $query, $dbh );
+ }
+ }
+ }
+ }
+
+ /**
+ * Change the current SQL mode, and ensure its WordPress compatibility.
+ *
+ * If no modes are passed, it will ensure the current MySQL server
+ * modes are compatible.
+ *
+ * @since 3.9.0
+ *
+ * @param array $modes Optional. A list of SQL modes to set.
+ */
+ public function set_sql_mode( $modes = array() ) {
+ if ( empty( $modes ) ) {
+ if ( $this->use_mysqli ) {
+ $res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' );
+ } else {
+ $res = mysql_query( 'SELECT @@SESSION.sql_mode', $this->dbh );
+ }
+
+ if ( empty( $res ) ) {
+ return;
+ }
+
+ if ( $this->use_mysqli ) {
+ $modes_array = mysqli_fetch_array( $res );
+ if ( empty( $modes_array[0] ) ) {
+ return;
+ }
+ $modes_str = $modes_array[0];