當前位置: 首頁>>代碼示例>>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: __construct

 /**
  * Create a new connection to the database
  *
  * @param string $host     The MySQL host
  * @param string $user     The MySQL user
  * @param string $password The MySQL password for the user
  * @param string $dbName   The MySQL database name
  *
  * @return Database A database object to interact with the database
  */
 public function __construct($host, $user, $password, $dbName)
 {
     if (Service::getContainer()) {
         if ($logger = Service::getContainer()->get('monolog.logger.mysql')) {
             $this->logger = $logger;
         }
     }
     $this->dbc = new mysqli($host, $user, $password, $dbName);
     if ($this->dbc->connect_errno) {
         $this->logger->addAlert($this->dbc->connect_error);
         throw new Exception($this->dbc->connect_error, $this->dbc->connect_errno);
     }
     $this->dbc->set_charset("utf8");
 }
開發者ID:kleitz,項目名稱:bzion,代碼行數:24,代碼來源:Database.php

示例2: connect

 public function connect($parameters, $selectDB = false)
 {
     // Normally $selectDB is set to false by the MySQLDatabase controller, as per convention
     $selectedDB = $selectDB && !empty($parameters['database']) ? $parameters['database'] : null;
     // Connection charset and collation
     $connCharset = Config::inst()->get('MySQLDatabase', 'connection_charset');
     $connCollation = Config::inst()->get('MySQLDatabase', 'connection_collation');
     if (!empty($parameters['port'])) {
         $this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password'], $selectedDB, $parameters['port']);
     } else {
         $this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password'], $selectedDB);
     }
     if ($this->dbConn->connect_error) {
         $this->databaseError("Couldn't connect to MySQL database | " . $this->dbConn->connect_error);
     }
     // Set charset and collation if given and not null. Can explicitly set to empty string to omit
     $charset = isset($parameters['charset']) ? $parameters['charset'] : $connCharset;
     if (!empty($charset)) {
         $this->dbConn->set_charset($charset);
     }
     $collation = isset($parameters['collation']) ? $parameters['collation'] : $connCollation;
     if (!empty($collation)) {
         $this->dbConn->query("SET collation_connection = {$collation}");
     }
 }
開發者ID:assertchris,項目名稱:silverstripe-framework,代碼行數:25,代碼來源:MySQLiConnector.php

示例3: __construct

 public function __construct($hostname, $username, $password, $database)
 {
     $this->link = @new mysqli($hostname, $username, $password, $database);
     if (mysqli_connect_error()) {
         trigger_error('Error: Could not connect to database "' . $database . '"', E_USER_WARNING);
         die;
     }
     $this->link->set_charset('utf8');
     $this->link->query("SET SQL_MODE = ''");
 }
開發者ID:Cyberdelia1987,項目名稱:audioproduct,代碼行數:10,代碼來源:mysql.php

示例4: _init_mysql

 /**
  * 初始化數據庫
  * 
  * @param array $config 數據庫配置
  */
 protected static function _init_mysql($config = array())
 {
     if ($config == NULL) {
         $config = $GLOBALS['config']['db'];
     }
     if (!self::$db) {
         self::$db = new mysqli($config['host'], $config['user'], $config['password'], $config['db_name']);
         if (0 == self::$db->connect_errno) {
             self::$db->set_charset('utf8');
         } else {
             echo 'MySQL connect error' . PHP_EOL;
         }
     }
 }
開發者ID:codergma,項目名稱:myspider2,代碼行數:19,代碼來源:CG_DB.php

示例5: __construct

 /**
  * Constructor
  *
  * @param array $connectionData Connection Data parsed by parse_url()
  */
 public function __construct(array $connectionData)
 {
     if (!self::isAvailable()) {
         error("MySQLi not installed - Update your PHP configuration");
     }
     $port = isset($connectionData["port"]) ? (int) $connectionData["port"] : 3306;
     $pass = isset($connectionData["pass"]) ? $connectionData["pass"] : NULL;
     $db = trim($connectionData["path"], "/ ");
     $this->dbname = $db;
     $this->user = $connectionData["user"];
     $this->password = $pass;
     $this->host = $connectionData["host"];
     $this->port = $port;
     $this->mysqli = new MySQLi($this->host, $this->user, $this->password, $this->dbname, $this->port);
     $this->testError();
     $this->mysqli->set_charset(str_replace("-", "", CHOQ::$encoding));
 }
開發者ID:nonconforme,項目名稱:nreeda,代碼行數:22,代碼來源:Mysql.class.php

示例6: connect

 public function connect($parameters, $selectDB = false)
 {
     // Normally $selectDB is set to false by the MySQLDatabase controller, as per convention
     $selectedDB = $selectDB && !empty($parameters['database']) ? $parameters['database'] : null;
     if (!empty($parameters['port'])) {
         $this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password'], $selectedDB, $parameters['port']);
     } else {
         $this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password'], $selectedDB);
     }
     if ($this->dbConn->connect_error) {
         $this->databaseError("Couldn't connect to MySQL database | " . $this->dbConn->connect_error);
     }
     // Set charset if given and not null. Can explicitly set to empty string to omit
     $charset = isset($parameters['charset']) ? $parameters['charset'] : 'utf8';
     if (!empty($charset)) {
         $this->dbConn->set_charset($charset);
     }
 }
開發者ID:nicocin,項目名稱:silverstripe-framework,代碼行數:18,代碼來源:MySQLiConnector.php

示例7:

 function set_charset($charset)
 {
     if (parent::set_charset($charset)) {
         return true;
     }
     // the client library may not support utf8mb4
     parent::set_charset('utf8');
     return $this->query("SET NAMES {$charset}");
 }
開發者ID:tomec-martin,項目名稱:adminer,代碼行數:9,代碼來源:mysqlssl.inc.php

示例8: getInstance

 /**
  * Obtiene una instancia de un objeto de conexion a la base de datos
  * @param array $parametros
  * @return \mysqli Mysqli Instance
  * @throws string
  */
 public static function getInstance(array $parametros = array())
 {
     if (self::$instance) {
         return self::$instance;
     }
     $parametrosRequeridos = array("host", "user", "pass", "db");
     \Validator::validateArrayKeys($parametrosRequeridos, $parametros);
     if (!array_key_exists("port", $parametros)) {
         $parametros["port"] = 3306;
     } elseif (empty($parametros["port"])) {
         $parametros["port"] = 3306;
     }
     $mysqli = new \MySQLi(\Validator::emptyString($parametros["host"]), \Validator::emptyString($parametros["user"]), $parametros["pass"], \Validator::emptyString($parametros["db"]), \Validator::int($parametros["port"]));
     if ($mysqli->connect_error) {
         $msg = "No se pudo conectar a la base de datos " . $mysqli->connect_errno . ':' . $mysqli->error;
         throw new Exception($msg);
     }
     $mysqli->set_charset("utf8");
     self::$instance = $mysqli;
     return self::$instance;
 }
開發者ID:elgodmaster,項目名稱:lacalderadeldiablo,代碼行數:27,代碼來源:Singleton.class.php

示例9: MySQLi

* @package  Handy-q 
* @author   JJuan <javier@textblock.org> 
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License 
* @link     http://www.textblock.org 
*/
require '../lang/spanish.lang.php';
$db_name = "handyq";
// The database we created earlier in phpMyAdmin.
$db_server = "localhost";
// Change if you have this hosted.
$db_user = "root";
// Your USERNAME
$db_pass = "";
// Your PASSWORD. Working locally, mine is blank. Change if you plan on deploying.
$mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error());
$mysqli->set_charset("utf8");
@($id = (int) $_GET['id']);
$sql = mysqli_query($mysqli, "SELECT * FROM docmanager WHERE id = {$id} ");
$data = mysqli_fetch_row($sql);
// Aktionen
$aktion = '';
if (isset($_GET['aktion'])) {
    $aktion = $_GET['aktion'];
}
if ($aktion == "") {
    echo 'Admin Area';
}
if ($aktion == "print") {
    $sql = mysqli_query($mysqli, "SELECT * FROM docmanager ORDER BY fecha DESC");
    echo '<table class="sortable">';
    echo '<caption>' . DOCMANAGER_PRINT . '</caption>';
開發者ID:pabalexa,項目名稱:handyq03,代碼行數:31,代碼來源:docmanagerprint.php

示例10: db_connect

    /**
     * Database connection
     *
     * @param	bool	$persistent
     * @return	object
     */
    public function db_connect($persistent = FALSE)
    {
        // Do we have a socket path?
        if ($this->hostname[0] === '/') {
            $hostname = NULL;
            $port = NULL;
            $socket = $this->hostname;
        } else {
            // Persistent connection support was added in PHP 5.3.0
            $hostname = $persistent === TRUE && is_php('5.3') ? 'p:' . $this->hostname : $this->hostname;
            $port = empty($this->port) ? NULL : $this->port;
            $socket = NULL;
        }
        $client_flags = $this->compress === TRUE ? MYSQLI_CLIENT_COMPRESS : 0;
        $this->_mysqli = mysqli_init();
        $this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
        if (isset($this->stricton)) {
            if ($this->stricton) {
                $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
            } else {
                $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode =
					REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
					@@sql_mode,
					"STRICT_ALL_TABLES,", ""),
					",STRICT_ALL_TABLES", ""),
					"STRICT_ALL_TABLES", ""),
					"STRICT_TRANS_TABLES,", ""),
					",STRICT_TRANS_TABLES", ""),
					"STRICT_TRANS_TABLES", "")');
            }
        }
        if (is_array($this->encrypt)) {
            $ssl = array();
            empty($this->encrypt['ssl_key']) or $ssl['key'] = $this->encrypt['ssl_key'];
            empty($this->encrypt['ssl_cert']) or $ssl['cert'] = $this->encrypt['ssl_cert'];
            empty($this->encrypt['ssl_ca']) or $ssl['ca'] = $this->encrypt['ssl_ca'];
            empty($this->encrypt['ssl_capath']) or $ssl['capath'] = $this->encrypt['ssl_capath'];
            empty($this->encrypt['ssl_cipher']) or $ssl['cipher'] = $this->encrypt['ssl_cipher'];
            if (!empty($ssl)) {
                if (isset($this->encrypt['ssl_verify'])) {
                    if ($this->encrypt['ssl_verify']) {
                        defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE);
                    } elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT')) {
                        $this->_mysqli->options(MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT, TRUE);
                    }
                }
                $client_flags |= MYSQLI_CLIENT_SSL;
                $this->_mysqli->ssl_set(isset($ssl['key']) ? $ssl['key'] : NULL, isset($ssl['cert']) ? $ssl['cert'] : NULL, isset($ssl['ca']) ? $ssl['ca'] : NULL, isset($ssl['capath']) ? $ssl['capath'] : NULL, isset($ssl['cipher']) ? $ssl['cipher'] : NULL);
            }
        }
        if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)) {
            // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
            if ($client_flags & MYSQLI_CLIENT_SSL && version_compare($this->_mysqli->client_info, '5.7.3', '<=') && empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)) {
                $this->_mysqli->close();
                $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
                log_message('error', $message);
                return $this->db->db_debug ? $this->db->display_error($message, '', TRUE) : FALSE;
            }
            if (!$this->_mysqli->set_charset($this->char_set)) {
                log_message('error', "Database: Unable to set the configured connection charset ('{$this->char_set}').");
                $this->_mysqli->close();
                return $this->db->db_debug ? $this->display_error('db_unable_to_set_charset', $this->char_set) : FALSE;
            }
            return $this->_mysqli;
        }
        return FALSE;
    }
開發者ID:axlyody,項目名稱:daijoubucms,代碼行數:73,代碼來源:mysqli_driver.php

示例11: num_rows

    {
        return mysql_fetch_array($consulta);
    }
    public function num_rows($consulta)
    {
        return mysql_num_rows($consulta);
    }
    public function getTotalConsultas()
    {
        return $this->total_consultas;
    }
}
$db_name = "handyq";
// The database we created earlier in phpMyAdmin.
$db_server = "localhost";
// Change if you have this hosted.
$db_user = "root";
// Your USERNAME
$db_pass = "";
// Your PASSWORD. Working locally, mine is blank. Change if you plan on deploying.
$mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error());
$mysqli->set_charset("iso 8859-1");
// Para editdeletedocs, de manera que pueda llamar a este archivo y no al suyo
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "handyq";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
mysql_query("SET NAMES 'iso 8859-1'");
開發者ID:pabalexa,項目名稱:handyq03,代碼行數:31,代碼來源:mysqlpdf.php

示例12: MySQLi

$url = DEFAULT_URL . '/';
if (isset($_GET['slug'])) {
    $slug = $_GET['slug'];
    if ('@' == $slug) {
        $url = 'https://twitter.com/' . TWITTER_USERNAME;
    } else {
        if (' ' == $slug) {
            // +
            $url = 'https://plus.google.com/u/0/' . GOOGLE_PLUS_ID . '/posts';
        } else {
            $slug = preg_replace('/[^a-z0-9]/si', '', $slug);
            if (is_numeric($slug) && strlen($slug) > 8) {
                $url = 'https://twitter.com/' . TWITTER_USERNAME . '/status/' . $slug;
            } else {
                $db = new MySQLi(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
                $db->set_charset('utf8mb4');
                $escapedSlug = $db->real_escape_string($slug);
                $redirectResult = $db->query('SELECT url FROM redirect WHERE slug = "' . $escapedSlug . '"');
                if ($redirectResult && $redirectResult->num_rows > 0) {
                    $db->query('UPDATE redirect SET hits = hits + 1 WHERE slug = "' . $escapedSlug . '"');
                    $url = $redirectResult->fetch_object()->url;
                } else {
                    $url = DEFAULT_URL . $_SERVER['REQUEST_URI'];
                }
                $db->close();
            }
        }
    }
}
header('Location: ' . $url, null, 301);
$attributeValue = htmlspecialchars($url);
開發者ID:abcselect,項目名稱:php-url-shortener,代碼行數:31,代碼來源:index.php

示例13: connect

    /**
     * Connect to the database.
     *
     * @param bool $persistent
     * @return mixed
     */
    public function connect($persistent = false)
    {
        // Do we have a socket path?
        if ($this->hostname[0] === '/') {
            $hostname = null;
            $port = null;
            $socket = $this->hostname;
        } else {
            $hostname = $persistent === true ? 'p:' . $this->hostname : $this->hostname;
            $port = empty($this->port) ? null : $this->port;
            $socket = null;
        }
        $client_flags = $this->compress === true ? MYSQLI_CLIENT_COMPRESS : 0;
        $this->mysqli = mysqli_init();
        $this->mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
        if (isset($this->strictOn)) {
            if ($this->strictOn) {
                $this->mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
            } else {
                $this->mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode =
					REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
					@@sql_mode,
					"STRICT_ALL_TABLES,", ""),
					",STRICT_ALL_TABLES", ""),
					"STRICT_ALL_TABLES", ""),
					"STRICT_TRANS_TABLES,", ""),
					",STRICT_TRANS_TABLES", ""),
					"STRICT_TRANS_TABLES", "")');
            }
        }
        if (is_array($this->encrypt)) {
            $ssl = [];
            empty($this->encrypt['ssl_key']) or $ssl['key'] = $this->encrypt['ssl_key'];
            empty($this->encrypt['ssl_cert']) or $ssl['cert'] = $this->encrypt['ssl_cert'];
            empty($this->encrypt['ssl_ca']) or $ssl['ca'] = $this->encrypt['ssl_ca'];
            empty($this->encrypt['ssl_capath']) or $ssl['capath'] = $this->encrypt['ssl_capath'];
            empty($this->encrypt['ssl_cipher']) or $ssl['cipher'] = $this->encrypt['ssl_cipher'];
            if (!empty($ssl)) {
                if (isset($this->encrypt['ssl_verify'])) {
                    if ($this->encrypt['ssl_verify']) {
                        defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
                    } elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT')) {
                        $this->mysqli->options(MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT, true);
                    }
                }
                $client_flags |= MYSQLI_CLIENT_SSL;
                $this->mysqli->ssl_set(isset($ssl['key']) ? $ssl['key'] : null, isset($ssl['cert']) ? $ssl['cert'] : null, isset($ssl['ca']) ? $ssl['ca'] : null, isset($ssl['capath']) ? $ssl['capath'] : null, isset($ssl['cipher']) ? $ssl['cipher'] : null);
            }
        }
        if ($this->mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)) {
            // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
            if ($client_flags & MYSQLI_CLIENT_SSL && version_compare($this->mysqli->client_info, '5.7.3', '<=') && empty($this->mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)) {
                $this->mysqli->close();
                $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
                log_message('error', $message);
                if ($this->db->db_debug) {
                    throw new DatabaseException($message);
                }
                return false;
            }
            if (!$this->mysqli->set_charset($this->charset)) {
                log_message('error', "Database: Unable to set the configured connection charset ('{$this->charset}').");
                $this->mysqli->close();
                if ($this->db->debug) {
                    throw new DatabaseException('Unable to set client connection character set: ' . $this->charset);
                }
                return false;
            }
            return $this->mysqli;
        }
        return false;
    }
開發者ID:titounnes,項目名稱:CodeIgniter4,代碼行數:78,代碼來源:Connection.php

示例14: intval

<?php

require 'config.php';
$url = DEFAULT_URL . '/';
if (isset($_GET['id'])) {
    $id = intval($_GET['id'], 36);
    if (!empty($id)) {
        $db = new MySQLi(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
        $db->set_charset('utf8');
        $result = $db->query("SELECT url FROM redirect WHERE id = {$id}");
        if ($result && $result->num_rows > 0) {
            $url = $result->fetch_object()->url;
        }
        $db->close();
    }
}
header('Location: ' . $url, null, 302);
exit;
開發者ID:ryanmcdonnell,項目名稱:php-url-shortener,代碼行數:18,代碼來源:index.php

示例15: MySQLi

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Post a Message</title>
</head>
<body>
<?php 
// This is an OOP version of the script from Chapter 13.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Validate the data (omitted)!
    // Connect to the database:
    $mysqli = new MySQLi('localhost', 'root', '', 'forum');
    $mysqli->set_charset('utf8');
    // Make the query:
    $q = 'INSERT INTO messages (forum_id, parent_id, user_id, subject, body, date_entered) VALUES (?, ?, ?, ?, ?, NOW())';
    // Prepare the statement:
    $stmt = $mysqli->prepare($q);
    // Bind the variables:
    $stmt->bind_param('iiiss', $forum_id, $parent_id, $user_id, $subject, $body);
    // Assign the values to variables:
    $forum_id = (int) $_POST['forum_id'];
    $parent_id = (int) $_POST['parent_id'];
    $user_id = 3;
    // The user_id value would normally come from the session.
    $subject = strip_tags($_POST['subject']);
    $body = strip_tags($_POST['body']);
    // Execute the query:
    $stmt->execute();
    // Print a message based upon the result:
    if ($stmt->affected_rows == 1) {
開發者ID:cuidezhu,項目名稱:phpmysql4_scripts,代碼行數:31,代碼來源:post_message.php


注:本文中的MySQLi::set_charset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。