当前位置: 首页>>代码示例>>PHP>>正文


PHP resource::set_charset方法代码示例

本文整理汇总了PHP中resource::set_charset方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::set_charset方法的具体用法?PHP resource::set_charset怎么用?PHP resource::set_charset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在resource的用法示例。


在下文中一共展示了resource::set_charset方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Connect to a MySQL database.
  * @param array $parameters An map of parameters, which should include:
  *  - server: The server, eg, localhost
  *  - username: The username to log on with
  *  - password: The password to log on with
  *  - database: The database to connect to
  *  - timezone: (optional) The timezone offset. For example: +12:00, "Pacific/Auckland", or "SYSTEM"
  */
 public function __construct($parameters)
 {
     $this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password']);
     if ($this->dbConn->connect_error) {
         $this->databaseError("Couldn't connect to MySQL database | " . $this->dbConn->connect_error);
     }
     $this->query("SET sql_mode = 'ANSI'");
     if (self::$connection_charset) {
         $this->dbConn->set_charset(self::$connection_charset);
     }
     $this->active = $this->dbConn->select_db($parameters['database']);
     $this->database = $parameters['database'];
     if (isset($parameters['timezone'])) {
         $this->query(sprintf("SET SESSION time_zone = '%s'", $parameters['timezone']));
     }
 }
开发者ID:normann,项目名称:sapphire,代码行数:25,代码来源:MySQLDatabase.php

示例2: __construct

 /**
  * Connect to a MySQL database.
  * @param array $parameters An map of parameters, which should include:
  *  - server: The server, eg, localhost
  *  - username: The username to log on with
  *  - password: The password to log on with
  *  - database: The database to connect to
  *  - timezone: (optional) The timezone offset. For example: +12:00, "Pacific/Auckland", or "SYSTEM"
  */
 public function __construct($parameters)
 {
     $this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password']);
     if ($this->dbConn->connect_error) {
         $this->databaseError("Couldn't connect to MySQL database | " . $this->dbConn->connect_error);
     }
     /* $this->query("SET sql_mode = 'ANSI'"); */
     /* Risoluzione errore "only_full_group_by" (http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_ansi) */
     $this->query("SET sql_mode = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");
     if (self::$connection_charset) {
         $this->dbConn->set_charset(self::$connection_charset);
     }
     $this->active = $this->dbConn->select_db($parameters['database']);
     $this->database = $parameters['database'];
     if (isset($parameters['timezone'])) {
         $this->query(sprintf("SET SESSION time_zone = '%s'", $parameters['timezone']));
     }
 }
开发者ID:comperio,项目名称:silverstripe-framework,代码行数:27,代码来源:MySQLDatabase.php

示例3: unset

 /**
  * @dataProvider data_strip_invalid_text
  * @ticket 21212
  */
 function test_strip_invalid_text($data, $expected, $message)
 {
     if (version_compare(PHP_VERSION, '5.3', '<') && stristr(php_uname('s'), 'win')) {
         $this->markTestSkipped('This test fails in PHP 5.2 on Windows. See https://core.trac.wordpress.org/ticket/31262');
     }
     $charset = self::$_wpdb->charset;
     if (isset($data[0]['connection_charset'])) {
         $new_charset = $data[0]['connection_charset'];
         unset($data[0]['connection_charset']);
     } else {
         $new_charset = $data[0]['charset'];
     }
     self::$_wpdb->charset = $new_charset;
     self::$_wpdb->set_charset(self::$_wpdb->dbh, $new_charset);
     $actual = self::$_wpdb->strip_invalid_text($data);
     self::$_wpdb->charset = $charset;
     self::$_wpdb->set_charset(self::$_wpdb->dbh, $charset);
     $this->assertSame($expected, $actual, $message);
 }
开发者ID:plis197715,项目名称:wordpress-develop,代码行数:23,代码来源:charset.php

示例4: __construct

 /**
  * Connect to a MySQL database.
  * @param array $parameters An map of parameters, which should include:
  *  - server: The server, eg, localhost
  *  - username: The username to log on with
  *  - password: The password to log on with
  *  - database: The database to connect to
  *  - timezone: (optional) The timezone offset. For example: +12:00, "Pacific/Auckland", or "SYSTEM"
  */
 public function __construct($parameters)
 {
     if (!empty($parameters['port'])) {
         $this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password'], '', $parameters['port']);
     } else {
         $this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password']);
     }
     if ($this->dbConn->connect_error) {
         $this->databaseError("Couldn't connect to MySQL database | " . $this->dbConn->connect_error);
     }
     $this->query("SET sql_mode = 'ANSI'");
     if (Config::inst()->get('MySQLDatabase', 'connection_charset')) {
         $this->dbConn->set_charset(Config::inst()->get('MySQLDatabase', 'connection_charset'));
     }
     $this->active = $this->dbConn->select_db($parameters['database']);
     $this->database = $parameters['database'];
     if (isset($parameters['timezone'])) {
         $this->query(sprintf("SET SESSION time_zone = '%s'", $parameters['timezone']));
     }
 }
开发者ID:hemant-chakka,项目名称:awss,代码行数:29,代码来源:MySQLDatabase.php

示例5: setConnectionCharset

 /**
  * Set character set of the MySQL-connection.
  *
  * Trys to set  the connection charset and returns it.
  * Throw Exception on failure.
  *
  * @param string $charset
  * @throws Exception
  *
  * @return string
  */
 public function setConnectionCharset($charset = 'utf8')
 {
     if (!$this->_mysqli instanceof mysqli) {
         $this->dbConnect();
     }
     if (!@$this->_mysqli->set_charset($charset)) {
         $this->sqlError($charset . ' ' . $this->_mysqli->error, $this->_mysqli->errno);
     }
     $this->connectionCharset = $this->_mysqli->character_set_name();
     return $this->connectionCharset;
 }
开发者ID:MichaelFichtner,项目名称:RadioLaFamilia,代码行数:22,代码来源:MsdDbMysqli.php

示例6: connect

 /**
  * Try to connect to the database
  */
 public function connect()
 {
     $this->mysqli = new Mysqli($this->config['host'], $this->config['user'], $this->config['password'], $this->config['name']);
     if ($this->mysqli->connect_errno) {
         printf("Connect failed: %s\n", $this->mysqli->connect_error);
         exit;
     }
     if ($this->config['charset']) {
         $this->mysqli->set_charset($this->config['charset']);
     }
     return $this;
 }
开发者ID:spirlici,项目名称:spcms,代码行数:15,代码来源:db.class.php

示例7: connect

 /**
  * Hace una conexión a la base de datos de MySQL
  *
  * @param array $config
  * @return resource_connection
  */
 public function connect($config)
 {
     if (!extension_loaded('mysqli')) {
         throw new KumbiaException('Debe cargar la extensión de PHP llamada php_mysqli');
     }
     $this->id_connection = new mysqli($config['host'], $config['username'], $config['password'], $config['name'], $config['port']);
     //no se usa $object->error() ya que solo funciona a partir de 5.2.9 y 5.3
     if (mysqli_connect_error()) {
         throw new KumbiaException(mysqli_connect_error());
     }
     //Selecciona charset
     if (isset($config['charset'])) {
         $this->id_connection->set_charset($config['charset']);
     }
     return TRUE;
 }
开发者ID:jaigjaig,项目名称:usuario_auth_template_bootstrap,代码行数:22,代码来源:mysqli.php

示例8:

	/**
	 * @dataProvider data_strip_invalid_text
	 * @ticket 21212
	 */
	function test_strip_invalid_text( $data, $expected, $message ) {
		$charset = self::$_wpdb->charset;
		if ( isset( $data[0]['connection_charset'] ) ) {
			$new_charset = $data[0]['connection_charset'];
			unset( $data[0]['connection_charset'] );
		} else {
			$new_charset = $data[0]['charset'];
		}

		self::$_wpdb->charset = $new_charset;
		self::$_wpdb->set_charset( self::$_wpdb->dbh, $new_charset );

		$actual = self::$_wpdb->strip_invalid_text( $data );

		self::$_wpdb->charset = $charset;
		self::$_wpdb->set_charset( self::$_wpdb->dbh, $charset );

		$this->assertSame( $expected, $actual, $message );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:23,代码来源:charset.php

示例9: connect

 /**
  * 连接数据库
  *
  * @return \mysqli|null|resource
  * @throws MysqlConnectException
  */
 public function connect()
 {
     if (is_null($this->mysql)) {
         $this->mysql = new \mysqli($this->host, $this->user, $this->password, $this->database, $this->port);
         $errno = $this->mysql->connect_errno;
         $error = $this->mysql->connect_error;
         if ($errno > 0) {
             $this->errno = $errno;
             $this->error = $error;
             $this->mysql->close();
             throw new MysqlConnectException($error, $errno);
         } else {
             $this->mysql->query('SET NAMES UTF8');
             $this->mysql->set_charset($this->charset);
         }
         return $this->mysql;
     } else {
         return $this->mysql;
     }
 }
开发者ID:qazzhoubin,项目名称:emptyphp,代码行数:26,代码来源:Connector.php

示例10: createConnection

 /**
  * Creates the connection to the MySQL DB through the MySQLi interface
  * 
  * @param boolean $useExceptions (optional) | Override on whether to use exceptions.  If not passed will use _DB_USE_EXCEPTIONS
  * @return boolean | TRUE on success (connection was made) / FALSE on failure
  * @throws _Exception | If _DB_USE_EXCEPTIONS is TRUE, will throw an exception instead of returning
  * false on connection error
  */
 private function createConnection($useExceptions = _DbConfig::USE_EXCEPTIONS)
 {
     $this->mysqli = new \mysqli($this->host, $this->username, $this->password, $this->dbName, $this->port, $this->socket);
     if (mysqli_connect_errno()) {
         $msg = 'Unable to connect to MySQL | ' . mysqli_connect_error();
         if ($useExceptions) {
             _Log::fatal($msg);
             $_e = new _Exception($msg, 0, $e);
             throw $_e;
         } else {
             _Log::warn($msg);
         }
     }
     if (isset($this->mysqli) && $this->mysqli !== NULL) {
         // set charset
         $rc = $this->mysqli->set_charset(_DbConfig::CHARSET);
         if ($rc !== TRUE) {
             _Log::warn('Error setting character set');
         }
         $this->isConnected = true;
         return TRUE;
     }
     return FALSE;
 }
开发者ID:kengoldfarb,项目名称:underscore_libs,代码行数:32,代码来源:_Db.php

示例11: set_charset

 /**
  * Sets the connection's character set.
  *
  * @since 3.1.0
  *
  * @param resource $dbh     The resource given by the driver
  * @param string   $charset Optional. The character set. Default null.
  * @param string   $collate Optional. The collation. Default null.
  */
 public function set_charset($dbh, $charset = null, $collate = null)
 {
     if (!isset($charset)) {
         $charset = $this->charset;
     }
     if (!isset($collate)) {
         $collate = $this->collate;
     }
     if (!$dbh->set_charset($charset, $collate)) {
         if ($this->has_cap('collation') && !empty($charset)) {
             $query = $this->prepare('SET NAMES %s', $charset);
             if (!empty($collate)) {
                 $query .= $this->prepare(' COLLATE %s', $collate);
             }
             $this->query($query);
         }
     }
 }
开发者ID:mpeshev,项目名称:wp-db-driver,代码行数:27,代码来源:db-driver.php

示例12: header

 /**
  * Send/set output charset in several output media in a proper way
  *
  * @param string   $mode [http|html|mysql|mysqli|pdo|text_email|html_email]
  * @param resource $conn The MySQL connection handler/the link identifier
  *                                  
  * @return string header formula if there is any (in cases of html, text_email, and html_email)
  * @author Khaled Al-Shamaa <khaled@ar-php.org>
  */
 public static function header($mode = 'http', $conn = null)
 {
     $mode = strtolower($mode);
     $head = '';
     switch ($mode) {
         case 'http':
             header('Content-Type: text/html; charset=' . $this->_outputCharset);
             break;
         case 'html':
             $head .= '<meta http-equiv="Content-type" content="text/html; charset=';
             $head .= $this->_outputCharset . '" />';
             break;
         case 'text_email':
             $head .= 'MIME-Version: 1.0\\r\\nContent-type: text/plain; charset=';
             $head .= $this->_outputCharset . '\\r\\n';
             break;
         case 'html_email':
             $head .= 'MIME-Version: 1.0\\r\\nContent-type: text/html; charset=';
             $head .= $this->_outputCharset . '\\r\\n';
             break;
         case 'mysql':
             if ($this->_outputCharset == 'utf-8') {
                 mysql_set_charset('utf8');
             } elseif ($this->_outputCharset == 'windows-1256') {
                 mysql_set_charset('cp1256');
             }
             break;
         case 'mysqli':
             if ($this->_outputCharset == 'utf-8') {
                 $conn->set_charset('utf8');
             } elseif ($this->_outputCharset == 'windows-1256') {
                 $conn->set_charset('cp1256');
             }
             break;
         case 'pdo':
             if ($this->_outputCharset == 'utf-8') {
                 $conn->exec('SET NAMES utf8');
             } elseif ($this->_outputCharset == 'windows-1256') {
                 $conn->exec('SET NAMES cp1256');
             }
             break;
     }
     return $head;
 }
开发者ID:pmaonline,项目名称:limesurvey-quickstart,代码行数:53,代码来源:Arabic.php


注:本文中的resource::set_charset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。