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


PHP mysqli_set_charset函数代码示例

本文整理汇总了PHP中mysqli_set_charset函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_set_charset函数的具体用法?PHP mysqli_set_charset怎么用?PHP mysqli_set_charset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: dbConnect

function dbConnect()
{
    $conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysqli_select_db($conn, DB_NAME);
    mysqli_set_charset($conn, 'utf8');
    return $conn;
}
开发者ID:zheyizhifeng,项目名称:dealer,代码行数:7,代码来源:db_helper.php

示例2: listarProductosSQL

function listarProductosSQL()
{
    //Creamos la conexión con la función anterior
    $conexion = ConectarDB();
    //generamos la consulta
    mysqli_set_charset($conexion, "utf8");
    //formato de datos utf8
    $sql = "SELECT *\tFROM producto";
    if (!($result = mysqli_query($conexion, $sql))) {
        die;
    }
    //si la conexión falla cancelar programa
    $productos = array();
    //creamos un array
    //guardamos en un array multidimensional todos los datos de la consulta
    $i = 0;
    while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
        $productos[$i] = $row;
        $i++;
    }
    desconectarDB($conexion);
    //desconectamos la base de datos
    return $productos;
    //devolvemos el array
}
开发者ID:jamesgarzon,项目名称:instruequipos,代码行数:25,代码来源:ListarProductosSQL.php

示例3: __construct

 public function __construct()
 {
     $this->db = new database();
     $con = $this->db->connect("localhost", "root", "revive", "server");
     mysqli_set_charset($con, "utf8");
     $this->debugger = new debugger();
 }
开发者ID:phoe721,项目名称:phoe721.com,代码行数:7,代码来源:login.php

示例4: cs_sql_connect

function cs_sql_connect($cs_db, $test = 0)
{
    $error = '';
    if (!extension_loaded('mysqli')) {
        $error = 'PHP extension mysqli must be activated!';
    } else {
        $connect = mysqli_connect($cs_db['place'], $cs_db['user'], $cs_db['pwd'], $cs_db['name']) or $error = mysqli_connect_error();
    }
    global $cs_main;
    $sql_charset = strtolower($cs_main['charset']);
    if (empty($error) and $sql_charset == 'utf-8') {
        # since php 5.0.5 - depends on mysql libs, too
        if (function_exists('mysqli_set_charset')) {
            mysqli_set_charset($connect, 'utf8');
        } else {
            mysqli_query($connect, "SET NAMES 'utf8'") or $error = mysqli_error($connect);
        }
    }
    if (empty($test) and empty($error)) {
        return $connect;
    } elseif (empty($test)) {
        cs_error_sql(__FILE__, 'cs_sql_connect', $error, 1);
    } else {
        return $error;
    }
}
开发者ID:aberrios,项目名称:WEBTHESGO,代码行数:26,代码来源:mysqli.php

示例5: connect

 function connect($server, $db, $user, $password, $socketPath, $charset = null, $port = false)
 {
     $connection = false;
     if ($socketPath !== false) {
         ini_set("mysqli.default_socket", $socketPath);
     }
     if ($this->UsePersistentConnection == true) {
         // Only supported on PHP 5.3 (mysqlnd)
         if (version_compare(PHP_VERSION, '5.3') > 0) {
             $this->Server = 'p:' . $this->Server;
         } else {
             eZDebug::writeWarning('mysqli only supports persistent connections when using php 5.3 and higher', 'eZMySQLiDB::connect');
         }
     }
     eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
     $connection = mysqli_connect($server, $user, $password, null, (int) $port, $socketPath);
     $dbErrorText = mysqli_connect_error();
     eZPerfLogger::accumulatorStop('mysqli_connection');
     $maxAttempts = $this->connectRetryCount();
     $waitTime = $this->connectRetryWaitTime();
     $numAttempts = 1;
     while (!$connection && $numAttempts <= $maxAttempts) {
         sleep($waitTime);
         eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
         $connection = mysqli_connect($this->Server, $this->User, $this->Password, null, (int) $this->Port, $this->SocketPath);
         eZPerfLogger::accumulatorStop('mysqli_connection');
         $numAttempts++;
     }
     $this->setError();
     $this->IsConnected = true;
     if (!$connection) {
         eZDebug::writeError("Connection error: Couldn't connect to database. Please try again later or inform the system administrator.\n{$dbErrorText}", __CLASS__);
         $this->IsConnected = false;
         throw new eZDBNoConnectionException($server);
     }
     if ($this->IsConnected && $db != null) {
         eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
         $ret = mysqli_select_db($connection, $db);
         eZPerfLogger::accumulatorStop('mysqli_connection');
         if (!$ret) {
             //$this->setError();
             eZDebug::writeError("Connection error: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
             $this->IsConnected = false;
         }
     }
     if ($charset !== null) {
         $originalCharset = $charset;
         $charset = eZCharsetInfo::realCharsetCode($charset);
     }
     if ($this->IsConnected and $charset !== null) {
         eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
         $status = mysqli_set_charset($connection, eZMySQLCharset::mapTo($charset));
         eZPerfLogger::accumulatorStop('mysqli_connection');
         if (!$status) {
             $this->setError();
             eZDebug::writeWarning("Connection warning: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
         }
     }
     return $connection;
 }
开发者ID:gggeek,项目名称:ezperformancelogger,代码行数:60,代码来源:ezmysqlitracingdb.php

示例6: abrirConex

function abrirConex()
{
    global $conexion;
    // Conexión con el servidor de base de datos MySQL
    $conexion = mysqli_connect('localhost', 'root', '', 'auditoria');
    mysqli_set_charset($conexion, 'utf8');
}
开发者ID:JCarlosR,项目名称:AuditoriaPHP,代码行数:7,代码来源:funciones.php

示例7: db_Connect

function db_Connect($host = CMW_DB_HOST, $login = CMW_DB_LOGIN, $password = CMW_DB_PASSWORD, $name = CMW_DB_NAME, $port = _INI_MYSQLI_DEFAULT_PORT, $socket = _INI_MYSQLI_DEFAULT_SOCKET)
{
    // Safely call this multiple times, only the first time has any effect //
    if (!db_IsConnected()) {
        global $db;
        $db = mysqli_init();
        //mysqli_options($db, ...);
        if (defined('CMW_DB_PORT')) {
            $port = CMW_DB_PORT;
        }
        if (defined('CMW_DB_SOCKET')) {
            $socket = CMW_DB_SOCKET;
        }
        $flags = null;
        // Connect to the database //
        mysqli_real_connect($db, $host, $login, $password, $name, $port, $socket, $flags);
        // http://php.net/manual/en/mysqli.quickstart.connections.php
        if ($db->connect_errno) {
            db_Log("Failed to connect: (" . $db->connect_errno . ") " . $db->connect_error);
        }
        // Set character set to utf8mb4 mode (default is utf8mb3 (utf8). mb4 is required for Emoji)
        mysqli_set_charset($db, 'utf8mb4');
        // More info: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through
    }
}
开发者ID:LastResortGames,项目名称:ludumdare,代码行数:25,代码来源:db_mysql.php

示例8: db_connect

function db_connect()
{
    global $link;
    $link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Can not acces MySQL-server.');
    mysqli_set_charset($link, 'utf8');
    mysqli_select_db($link, DB_NAME) or die('Can not access database.');
}
开发者ID:vgartner,项目名称:Open-GPS-tracker,代码行数:7,代码来源:library.php

示例9: insertarTweetInfo

function insertarTweetInfo($id_tweet, $tweet, $rts, $favs, $fecha_creacion, $usuario, $url_imagen, $followers, $followings, $num_tweets)
{
    //Creamos la conexión a la base de datos
    $conexion = mysqli_connect("localhost", "root", "", "twitterdata");
    //Comprobamos laconexión
    if ($conexion) {
    } else {
        die('Ha sucedido un error inexperador en la conexion de la base de datos<br>');
    }
    //Codificación de la base de datos en utf8
    mysqli_query($conexion, "SET NAMES 'utf8'");
    mysqli_set_charset($conexion, "utf8");
    //Creamos la sentencia SQL para insertar los datos de entrada
    $sql = "insert into tweets (id_tweet,tweet,rt,fav,fecha_creacion,usuario,url_imagen,followers,followings,num_tweets) \n            values (" . $id_tweet . ",'" . $tweet . "'," . $rts . "," . $favs . ",'" . $fecha_creacion . "','" . $usuario . "','" . $url_imagen . "'," . $followers . "," . $followings . "," . $num_tweets . ");";
    $consulta = mysqli_query($conexion, $sql);
    //Comprobamos si la consulta ha tenido éxito
    if ($consulta) {
    } else {
        die("No se ha podido insertar en la base de datos<br><br>" . mysqli_error($conexion));
    }
    //Cerramos la conexión de la base de datos
    $close = mysqli_close($conexion);
    if ($close) {
    } else {
        die('Ha sucedido un error inexperado en la desconexion de la base de datos<br>');
    }
}
开发者ID:dmoreno19949,项目名称:Sentimientos_twitter,代码行数:27,代码来源:insertarBD.php

示例10: __construct

 /**
  * constructor(string $dsn)
  * Connect to MySQL server.
  */
 function __construct($dsn)
 {
     if (!is_callable("mysqli_connect")) {
         return $this->_setLastError("-1", "MySQLi extension is not loaded", "mysqli_connect");
     }
     if (!empty($dsn["persist"])) {
         if (version_compare(PHP_VERSION, '5.3') < 0) {
             return $this->_setLastError("-1", "Persistent connections in MySQLi is allowable since PHP 5.3", "mysqli_connect");
         } else {
             $dsn["host"] = "p:" . $dsn["host"];
         }
     }
     if (isset($dsn['socket'])) {
         // Socket connection
         $this->link = mysqli_connect(null, empty($dsn['user']) ? 'root' : $dsn['user'], empty($dsn['pass']) ? '' : $dsn['pass'], preg_replace('{^/}s', '', $dsn['path']), null, $dsn['socket']);
     } else {
         if (isset($dsn['host'])) {
             // Host connection
             $this->link = mysqli_connect($dsn['host'], empty($dsn['user']) ? 'root' : $dsn['user'], empty($dsn['pass']) ? '' : $dsn['pass'], preg_replace('{^/}s', '', $dsn['path']), empty($dsn['port']) ? null : $dsn['port']);
         } else {
             return $this->_setDbError('mysqli_connect()');
         }
     }
     $this->_resetLastError();
     if (!$this->link) {
         return $this->_setDbError('mysqli_connect()');
     }
     mysqli_set_charset($this->link, isset($dsn['enc']) ? $dsn['enc'] : 'UTF8');
 }
开发者ID:Sarjuuk,项目名称:DbSimple,代码行数:33,代码来源:Mysqli.php

示例11: Open

 /**
  * @inheritdocs
  */
 function Open($connectionstring, $database, $username, $password, $charset = '', $bootstrap = '')
 {
     if (!function_exists("mysqli_connect")) {
         throw new DatabaseException('mysqli extension is not enabled on this server.', DatabaseException::$CONNECTION_ERROR);
     }
     // if the port is provided in the connection string then strip it out and provide it as a separate param
     $hostAndPort = explode(":", $connectionstring);
     $host = $hostAndPort[0];
     $port = count($hostAndPort) > 1 ? $hostAndPort[1] : null;
     $connection = mysqli_connect($host, $username, $password, $database, $port);
     if (mysqli_connect_errno()) {
         throw new DatabaseException("Error connecting to database: " . mysqli_connect_error(), DatabaseException::$CONNECTION_ERROR);
     }
     if ($charset) {
         mysqli_set_charset($connection, $charset);
         if (mysqli_connect_errno()) {
             throw new DatabaseException("Unable to set charset: " . mysqli_connect_error(), DatabaseException::$CONNECTION_ERROR);
         }
     }
     if ($bootstrap) {
         $statements = explode(';', $bootstrap);
         foreach ($statements as $sql) {
             try {
                 $this->Execute($connection, $sql);
             } catch (Exception $ex) {
                 throw new DatabaseException("problem with bootstrap sql: " . $ex->getMessage(), DatabaseException::$ERROR_IN_QUERY);
             }
         }
     }
     return $connection;
 }
开发者ID:hpazevedo,项目名称:Teste-BDR,代码行数:34,代码来源:MySQLi.php

示例12: ActualizarProductoSQL

function ActualizarProductoSQL($productoAActualizar)
{
    $codigo = $productoAActualizar["codigo"];
    $detalle = $productoAActualizar["detalle"];
    $precioVenta = $productoAActualizar["precio_venta"];
    $precioCosto = $productoAActualizar["precio_costo"];
    $iva = $productoAActualizar["iva"];
    $stock = 0;
    $marca = $productoAActualizar["marca"];
    $esMateriaPrima = true;
    //Creamos la conexión con la función anterior
    $conexion = ConectarDB();
    //generamos la consulta
    mysqli_set_charset($conexion, "utf8");
    //formato de datos utf8
    $sql = "  UPDATE producto\n    SET detalle = '{$detalle}', precio_venta ='{$precioVenta}', precio_costo ='{$precioCosto}', iva ='{$iva}', stock = '{$stock}', marca='{$marca}', es_materia_prima='{$esMateriaPrima}'\n    WHERE codigo = '{$codigo}';";
    if (!($result = mysqli_query($conexion, $sql))) {
        die;
    }
    //si la conexión falla cancelar programa
    desconectarDB($conexion);
    //desconectamos la base de datos
    return true;
    // print_r($productos); //devolvemos el array
}
开发者ID:jamesgarzon,项目名称:instruequipos,代码行数:25,代码来源:ActualizarProductoSQL.php

示例13: db_connect

/**
   $host - hostname:port, hostname:socket, socket, where a socket is to be provided, the : is compulsory, even
   if its first character, in which case localhost is assumed
   
   @param $cache_link - if TRUE, save reference to link for reuse.
*/
function db_connect($host, $user, $passwd, $dbname, $charset = NULL, $cache_link = TRUE)
{
    global $_opendb_dblink;
    $index = strpos($host, ':');
    if ($index !== FALSE) {
        $port = substr($host, $index + 1);
        $host = substr($host, 0, $index);
        // probably a socket
        if (!is_numeric($port)) {
            $socket = $port;
            unset($port);
        }
    }
    if (strlen($socket) > 0) {
        $link = @mysqli_connect($host, $user, $passwd, $dbname, NULL, $socket);
    } else {
        if (strlen($port) > 0) {
            $link = @mysqli_connect($host, $user, $passwd, $dbname, $port);
        } else {
            $link = @mysqli_connect($host, $user, $passwd, $dbname);
        }
    }
    if ($link !== FALSE) {
        if ($cache_link) {
            $_opendb_dblink = $link;
        }
        if ($charset != NULL) {
            @mysqli_set_charset($link, $charset);
        }
        return $link;
    }
    //else
    return FALSE;
}
开发者ID:horrabin,项目名称:opendb,代码行数:40,代码来源:mysqli.inc.php

示例14: dbConnect

function dbConnect()
{
    //Connect to database
    // Access global variables
    global $mysqli;
    global $dbHost;
    global $dbUser;
    global $dbPass;
    global $dbName;
    if (!isset($mysqli)) {
        // Attempt to connect to database server
        if (isset($dbPort)) {
            $mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName, $dbPort);
        } else {
            $mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
        }
        // If connection failed...
        if ($mysqli->connect_error) {
            webhooks_debug(" == Failed to connect to database: " . $mysqli->connect_error . " == ", true);
        }
        // if ($mysqli->connect_error)
        global $charset;
        mysqli_set_charset($mysqli, isset($charset) ? $charset : "utf8");
    }
    // if(!isset($mysqli))
    return $mysqli;
}
开发者ID:amargautam,项目名称:sendy-webhooks,代码行数:27,代码来源:db.php

示例15: dbConnect

function dbConnect()
{
    ${"GLOBALS"}["ynvyvtgrlhv"] = "dbUser";
    global $mysqli;
    global $dbHost;
    global $dbUser;
    global $dbPass;
    global $dbName;
    global $dbPort;
    ${"GLOBALS"}["cdbebx"] = "mysqli";
    $luljlbwrlm = "charset";
    $qcnjjmjhshu = "dbPass";
    ${"GLOBALS"}["urqiwxbggy"] = "dbName";
    ${"GLOBALS"}["glxpgvwccp"] = "dbHost";
    if (isset(${${"GLOBALS"}["ptgzyszv"]})) {
        ${${"GLOBALS"}["mikmhj"]} = new mysqli(${${"GLOBALS"}["mxccww"]}, ${${"GLOBALS"}["ipgxwvjqcfs"]}, ${$qcnjjmjhshu}, ${${"GLOBALS"}["urqiwxbggy"]}, ${${"GLOBALS"}["ptgzyszv"]});
    } else {
        ${${"GLOBALS"}["mikmhj"]} = new mysqli(${${"GLOBALS"}["glxpgvwccp"]}, ${${"GLOBALS"}["ynvyvtgrlhv"]}, ${${"GLOBALS"}["ukyvrmxs"]}, ${${"GLOBALS"}["thiajcew"]});
    }
    if ($mysqli->connect_error) {
        fail("<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><link rel=\"Shortcut Icon\" type=\"image/ico\" href=\"/img/favicon.png\"><title>" . _("Can't connect to database") . "</title></head><style type=\"text/css\">body{background: #ffffff;font-family: Helvetica, Arial;}#wrapper{background: #f2f2f2;width: 300px;height: 130px;margin: -140px 0 0 -150px;position: absolute;top: 50%;left: 50%;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;}p{text-align: center;line-height: 18px;font-size: 12px;padding: 0 30px;}h2{font-weight: normal;text-align: center;font-size: 20px;}a{color: #000;}a:hover{text-decoration: none;}</style><body><div id=\"wrapper\"><p><h2>" . _("Can't connect to database") . "</h2></p><p>" . _("There is a problem connecting to the database. Please try again later or see this <a href=\"https://sendy.co/troubleshooting#cannot-connect-to-database\" target=\"_blank\">troubleshooting tip</a>.") . "</p></div></body></html>");
    }
    global $charset;
    mysqli_set_charset(${${"GLOBALS"}["mikmhj"]}, isset(${${"GLOBALS"}["iwcsixdue"]}) ? ${$luljlbwrlm} : "utf8");
    return ${${"GLOBALS"}["cdbebx"]};
}
开发者ID:ariestiyansyah,项目名称:nggadu,代码行数:26,代码来源:functions.php


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