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


PHP mysqli::set_charset方法代码示例

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


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

示例1: init

 /**
  * Prepare driver before mount volume.
  * Connect to db, check required tables and fetch root path
  *
  * @return bool
  * @author Dmitry (dio) Levashov
  **/
 protected function init()
 {
     if (!($this->options['host'] || $this->options['socket']) || !$this->options['user'] || !$this->options['pass'] || !$this->options['db'] || !$this->options['path'] || !$this->options['files_table']) {
         return false;
     }
     $this->db = new mysqli($this->options['host'], $this->options['user'], $this->options['pass'], $this->options['db'], $this->options['port'], $this->options['socket']);
     if ($this->db->connect_error || @mysqli_connect_error()) {
         return false;
     }
     $this->rootparameter($this->options['alias'], $this->options['defaults']['read'], $this->options['defaults']['write'], $this->options['defaults']['locked'], $this->options['defaults']['hidden']);
     $this->db->set_charset('utf8');
     if ($res = $this->db->query('SHOW TABLES')) {
         while ($row = $res->fetch_array()) {
             if ($row[0] == $this->options['files_table']) {
                 $this->tbf = $this->options['files_table'];
                 break;
             }
         }
     }
     if (!$this->tbf) {
         return false;
     }
     $this->updateCache($this->options['path'], $this->_stat($this->options['path']));
     return true;
 }
开发者ID:rajasharma27,项目名称:MySQL-DRIVE-With-elFinder,代码行数:32,代码来源:elFinderVolumeMySQL.class.php

示例2: init

 /**
  * Prepare driver before mount volume.
  * Connect to db, check required tables and fetch root path
  *
  * @return bool
  * @author Dmitry (dio) Levashov
  **/
 protected function init()
 {
     if (!($this->options['host'] || $this->options['socket']) || !$this->options['user'] || !$this->options['db'] || !$this->options['path'] || !$this->options['files_table']) {
         return false;
     }
     $this->db = new mysqli($this->options['host'], $this->options['user'], $this->options['pass'], $this->options['db'], $this->options['port'], $this->options['socket']);
     if ($this->db->connect_error || @mysqli_connect_error()) {
         echo mysql_error();
         exit;
         //return false;
     } else {
         //print_r($this->db);exit;
     }
     $this->db->set_charset('utf8');
     if ($res = $this->db->query('SHOW TABLES')) {
         while ($row = $res->fetch_array()) {
             if ($row[0] == $this->options['files_table']) {
                 $this->tbf = $this->options['files_table'];
                 break;
             }
         }
     }
     if (!$this->tbf) {
         return false;
     }
     $this->updateCache($this->options['path'], $this->_stat($this->options['path']));
     return true;
 }
开发者ID:ivanberry,项目名称:grw,代码行数:35,代码来源:elFinderVolumeMySQL.class.php

示例3: connect

 static function connect($host = 'localhost', $user, $password, $name = 'lychee')
 {
     # Check dependencies
     Module::dependencies(isset($host, $user, $password, $name));
     $database = new mysqli($host, $user, $password);
     # Check connection
     if ($database->connect_errno) {
         exit('Error: ' . $database->connect_error);
     }
     # Avoid sql injection on older MySQL versions by using GBK
     if ($database->server_version < 50500) {
         @$database->set_charset('GBK');
     } else {
         @$database->set_charset('utf8');
     }
     # Set unicode
     $database->query('SET NAMES utf8;');
     # Check database
     if (!$database->select_db($name)) {
         if (!Database::createDatabase($database, $name)) {
             exit('Error: Could not create database!');
         }
     }
     # Check tables
     $query = Database::prepare($database, 'SELECT * FROM ?, ?, ?, ? LIMIT 0', array(LYCHEE_TABLE_PHOTOS, LYCHEE_TABLE_ALBUMS, LYCHEE_TABLE_SETTINGS, LYCHEE_TABLE_LOG));
     if (!$database->query($query)) {
         if (!Database::createTables($database)) {
             exit('Error: Could not create tables!');
         }
     }
     return $database;
 }
开发者ID:TheMadav,项目名称:Lychee,代码行数:32,代码来源:Database.php

示例4: connect

 /**
  * connect to the database
  *
  * @param bool $selectdb select the database now?
  * @return bool successful?
  */
 public function connect($selectdb = true)
 {
     if (!extension_loaded('mysqli')) {
         trigger_error('notrace:mysqli extension not loaded', E_USER_ERROR);
         return false;
     }
     $this->allowWebChanges = $_SERVER['REQUEST_METHOD'] !== 'GET';
     if ($selectdb) {
         $dbname = constant('XOOPS_DB_NAME');
     } else {
         $dbname = '';
     }
     if (XOOPS_DB_PCONNECT == 1) {
         $this->conn = new mysqli('p:' . XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, $dbname);
     } else {
         $this->conn = new mysqli(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, $dbname);
     }
     // errno is 0 if connect was successful
     if (0 !== $this->conn->connect_errno) {
         return false;
     }
     if (defined('XOOPS_DB_CHARSET') && '' !== XOOPS_DB_CHARSET) {
         // $this->queryF("SET NAMES '" . XOOPS_DB_CHARSET . "'");
         $this->conn->set_charset(XOOPS_DB_CHARSET);
     }
     $this->queryF('SET SQL_BIG_SELECTS = 1');
     return true;
 }
开发者ID:geekwright,项目名称:XoopsCore25,代码行数:34,代码来源:mysqldatabase.php

示例5: Init

 /**
  * Инициализация соединения с БД.
  *
  */
 public static function Init()
 {
     //  Initcializatciia ob``ekta mysqli
     /* create a connection object which is not connected */
     try {
         self::$DB = mysqli_connect(DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME);
     } catch (Exception $e) {
         throw new Exception(mysqli_connect_error(), 500);
     }
     /* check connection */
     if (mysqli_connect_errno()) {
         die("mysqli - Unable to connect to the server or choose a database.<br>\n Cause: " . mysqli_connect_error());
     }
     self::$DB->set_charset('utf8');
     //  self::$DB = mysqli_init();
     /* set connection options */
     //  self::$DB->options(MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=1");
     //  self::$DB->options(MYSQLI_INIT_COMMAND, "SET CacheDataACTER SET UTF8");
     //  self::$DB->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
     /* connect to server */
     //  self::$DB->real_connect(DB_HOST, DB_LOGIN, DB_PASSW, DB_NAME);
     //  self::$DB->select_db(DB_NAME);
     //  Initcializatciia interfesa dlia raboty` s khranimy`mi protcedurami
     //    self::$Procedure = new DB_Procedure();
     //  mysql_query('SET CacheDataACTER SET UTF8');
     //  mysql_query('SET CacheDataACTER SET cp1251_koi8');
     //  mysql_query('set names cp1251');
     //  mysql_query("SET CacheDataACTER SET DEFAULT", self::$DB_Link);
 }
开发者ID:kshamiev,项目名称:testXml,代码行数:33,代码来源:DB.php

示例6: __construct

 private function __construct()
 {
     if (!class_exists('mysqli')) {
         emMsg('服务器空间PHP不支持MySqli函数');
     }
     @($this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWD, DB_NAME));
     if ($this->conn->connect_error) {
         switch ($this->conn->connect_errno) {
             case 1044:
             case 1045:
                 emMsg("连接数据库失败,数据库用户名或密码错误");
                 break;
             case 1049:
                 emMsg("连接数据库失败,未找到您填写的数据库");
                 break;
             case 2003:
                 emMsg("连接数据库失败,数据库端口错误");
                 break;
             case 2005:
                 emMsg("连接数据库失败,数据库地址错误或者数据库服务器不可用");
                 break;
             case 2006:
                 emMsg("连接数据库失败,数据库服务器不可用");
                 break;
             default:
                 emMsg("连接数据库失败,请检查数据库信息。错误编号:" . $this->conn->connect_errno);
                 break;
         }
     }
     $this->conn->set_charset('utf8');
 }
开发者ID:flyysr,项目名称:emlog,代码行数:31,代码来源:mysqlii.php

示例7: __construct

 /**
  * @param array  $params
  * @param string $username
  * @param string $password
  * @param array  $driverOptions
  *
  * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException
  */
 public function __construct(array $params, $username, $password, array $driverOptions = array())
 {
     $port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port');
     // Fallback to default MySQL port if not given.
     if (!$port) {
         $port = 3306;
     }
     $socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket');
     $dbname = isset($params['dbname']) ? $params['dbname'] : null;
     $flags = isset($driverOptions[static::OPTION_FLAGS]) ? $driverOptions[static::OPTION_FLAGS] : null;
     $this->_conn = mysqli_init();
     $this->setDriverOptions($driverOptions);
     $previousHandler = set_error_handler(function () {
     });
     if (!$this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) {
         set_error_handler($previousHandler);
         $sqlState = 'HY000';
         if (@$this->_conn->sqlstate) {
             $sqlState = $this->_conn->sqlstate;
         }
         throw new MysqliException($this->_conn->connect_error, $sqlState, $this->_conn->connect_errno);
     }
     set_error_handler($previousHandler);
     if (isset($params['charset'])) {
         $this->_conn->set_charset($params['charset']);
     }
 }
开发者ID:kirkbauer2,项目名称:kirkxc,代码行数:35,代码来源:MysqliConnection.php

示例8: connect

 /**
  * Connects to database.
  *
  * @param string $host
  * @param string $name
  * @param string $password
  * @param integer|null $port
  * @throws \RuntimeException
  */
 public function connect($host, $name, $password, $port = null)
 {
     $this->conn = @new \mysqli($host, $name, $password, $port);
     if (mysqli_connect_error() !== null) {
         throw new \RuntimeException('Cannot connect to database.');
     }
     $this->conn->set_charset('utf8');
 }
开发者ID:prepare4battle,项目名称:Ilch-2.0,代码行数:17,代码来源:Mysql.php

示例9: __construct

 /**
  * @param string $host What server is the database located on?
  * @param string $user What is the DB user
  * @param string $pass What is her password
  * @param string $database What is the name of the database that we want to query
  * @param int $port What port should we connect to
  *
  * @throws Exception
  */
 public function __construct($host, $user, $pass, $database, $port = 3306)
 {
     $this->mysqli = new mysqli($host, $user, $pass, $database, $port);
     $this->mysqli->set_charset("utf8");
     if ($this->mysqli->connect_errno) {
         throw new Exception("Failed to connect to MySQL: (" . $this->mysqli->connect_errno . ") " . $this->mysqli->connect_error);
     }
 }
开发者ID:sameg14,项目名称:PHPMastery,代码行数:17,代码来源:DBCommon.php

示例10: __construct

 public function __construct(array $params, $username, $password, array $driverOptions = array())
 {
     $port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port');
     $socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket');
     $this->_conn = new \mysqli($params['host'], $username, $password, $params['dbname'], $port, $socket);
     if (isset($params['charset'])) {
         $this->_conn->set_charset($params['charset']);
     }
 }
开发者ID:rodmen,项目名称:dbal,代码行数:9,代码来源:MysqliConnection.php

示例11: connect

 /**
  * Establishes db connection
  */
 private function connect($host, $user, $pwd, $dbname)
 {
     $this->database = mysqli_init();
     $this->database->real_connect($host, $user, $pwd, $dbname);
     if ($this->database === NULL || $this->database->connect_errno) {
         die("Failed to connect to database!");
     }
     $this->database->set_charset("utf8");
 }
开发者ID:netzbandit,项目名称:YAMPF,代码行数:12,代码来源:db.class.php

示例12: isOpen

 /**
  * Vérifie si la connection à la base de donnée est ouverte, la créer sinon
  */
 private static function isOpen()
 {
     if (self::$oMysqli == NULL) {
         $aDbConfig = Config::get('db');
         self::$oMysqli = new mysqli($aDbConfig['hostname'], $aDbConfig['username'], $aDbConfig['password'], $aDbConfig['name']);
         self::$oMysqli->set_charset("utf8");
     }
     return true;
 }
开发者ID:Jatax,项目名称:TKS,代码行数:12,代码来源:database.class.php

示例13:

 function __construct($host, $user, $password, $name = false)
 {
     if ($name) {
         $this->conn = new \mysqli($host, $user, $password, $name);
         $this->conn->set_charset('utf8');
     } else {
         $this->conn = new \mysqli($host, $user, $password);
     }
 }
开发者ID:boggad,项目名称:waddle-mvc,代码行数:9,代码来源:MysqlConnection.php

示例14: __construct

 /**
  * @param string $host
  * @param string $username
  * @param string $password
  * @param string $db
  * @param int $port
  */
 public function __construct($host, $username, $password, $db, $port = NULL)
 {
     if ($port == NULL) {
         $port = ini_get('mysqli.default_port');
     }
     $this->_mysqli = new mysqli($host, $username, $password, $db, $port) or die('Shrinkwrap could not connect to the pool');
     $this->_mysqli->set_charset('utf8');
     self::$_instance = $this;
 }
开发者ID:jakop345,项目名称:strike-search,代码行数:16,代码来源:shrinkWrap.php

示例15: __init

 protected function __init()
 {
     Config::_getInstance()->load('DB');
     $this->link = new mysqli(config('host', 'DB'), config('user', 'DB'), config('password', 'DB'), config('db', 'DB'));
     if ($this->link->connect_error) {
         $this->addError('connection', $this->link->connect_errno, $this->link->connect_error);
     }
     $this->link->set_charset(config('encoding', 'DB'));
 }
开发者ID:enderteszla,项目名称:phpframework-etc,代码行数:9,代码来源:DB.php


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