gcdb::set_charset()
最后更新于:2021-11-26 09:04:34
gcdb::set_charset( resource$dbh, string$charset=null, string$collate=null)Sets the connection’s character set.
参数
- $dbh
-
(resource) (Required) The resource given by mysql_connect.
- $charset
-
(string) (Optional) The character set.
Default value: null
- $collate
-
(string) (Optional) The collation.
Default value: null
源文件
文件: gc-includes/gc-db.php
public function set_charset( $dbh, $charset = null, $collate = null ) {
if ( ! isset( $charset ) ) {
$charset = $this->charset;
}
if ( ! isset( $collate ) ) {
$collate = $this->collate;
}
if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) {
$set_charset_succeeded = true;
if ( $this->use_mysqli ) {
if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
$set_charset_succeeded = mysqli_set_charset( $dbh, $charset );
}
if ( $set_charset_succeeded ) {
$query = $this->prepare( 'SET NAMES %s', $charset );
if ( ! empty( $collate ) ) {
$query .= $this->prepare( ' COLLATE %s', $collate );
}
mysqli_query( $dbh, $query );
}
} else {
if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
$set_charset_succeeded = mysql_set_charset( $charset, $dbh );
}
if ( $set_charset_succeeded ) {
$query = $this->prepare( 'SET NAMES %s', $charset );
if ( ! empty( $collate ) ) {
$query .= $this->prepare( ' COLLATE %s', $collate );
}
mysql_query( $query, $dbh );
}
}
}
}