本文整理汇总了PHP中mysql_set_charset函数的典型用法代码示例。如果您正苦于以下问题:PHP mysql_set_charset函数的具体用法?PHP mysql_set_charset怎么用?PHP mysql_set_charset使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysql_set_charset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: installWithoutDemo
public static function installWithoutDemo(JO_Db_Adapter_Abstract $db)
{
mysql_connect($db->getConfig('host'), $db->getConfig('username'), $db->getConfig('password'));
mysql_select_db($db->getConfig('dbname'));
mysql_set_charset('utf8');
$structure = APPLICATION_PATH . '/modules/install/structure.sql';
if (!file_exists($structure)) {
return false;
}
$queryes = self::getQueryes(file($structure));
$results = array();
foreach ($queryes as $query) {
if (trim($query)) {
try {
/*$results[] = */
(bool) mysql_query($query);
} catch (JO_Exception $e) {
/*$results[] = false;*/
}
}
}
$request = JO_Request::getInstance();
$results[] = $db->insert('users', array('user_id' => 1, 'username' => $request->getPost('username'), 'password' => md5(md5($request->getPost('password'))), 'register_datetime' => new JO_Db_Expr('NOW()'), 'status' => 'activate', 'groups' => 'a:1:{i:2;s:2:"on";}'));
/*$results[] = */
$db->update('system', array('value' => $request->getPost('admin_mail')), array('`key` = ?' => 'admin_mail'));
/*$results[] = */
$db->update('system', array('value' => $request->getPost('report_mail')), array('`key` = ?' => 'report_mail'));
if (!in_array(false, $results)) {
$db_set = "\r\r\n\tdb.adapter = \"MYSQLi\"\r\r\n\tdb.params.host = \"" . $db->getConfig('host') . "\"\r\r\n\tdb.params.username = \"" . $db->getConfig('username') . "\"\r\r\n\tdb.params.password = \"" . $db->getConfig('password') . "\"\r\r\n\tdb.params.dbname = \"" . $db->getConfig('dbname') . "\"\r\r\n\tdb.params.charset =\"utf8\"";
$results[] = (bool) @file_put_contents(APPLICATION_PATH . '/config/config_db.ini', $db_set);
}
return !in_array(false, $results);
}
示例2: connect
protected function connect()
{
if (!function_exists('mysql_connect')) {
// We have to '@' the actual call since it can spew all sorts of silly
// noise, but it will also silence fatals caused by not having MySQL
// installed, which has bitten me on three separate occasions. Make sure
// such failures are explicit and loud.
throw new Exception("About to call mysql_connect(), but the PHP MySQL extension is not " . "available!");
}
$user = $this->getConfiguration('user');
$host = $this->getConfiguration('host');
$database = $this->getConfiguration('database');
$pass = $this->getConfiguration('pass');
if ($pass instanceof PhutilOpaqueEnvelope) {
$pass = $pass->openEnvelope();
}
$conn = @mysql_connect($host, $user, $pass, $new_link = true, $flags = 0);
if (!$conn) {
$errno = mysql_errno();
$error = mysql_error();
throw new AphrontQueryConnectionException("Attempt to connect to {$user}@{$host} failed with error " . "#{$errno}: {$error}.", $errno);
}
if ($database !== null) {
$ret = @mysql_select_db($database, $conn);
if (!$ret) {
$this->throwQueryException($conn);
}
}
mysql_set_charset('utf8', $conn);
return $conn;
}
示例3: db_connect
function db_connect($host, $username, $password)
{
if ($r = mysql_connect($host, $username, $password)) {
mysql_set_charset('cp1251', $r);
}
return $r;
}
示例4: OpenConnection
function OpenConnection()
{
global $mysqlAuthentication;
global $sqlserverAuthentication;
$host = null;
$options = null;
if (isset($mysqlAuthentication)) {
$host = $mysqlAuthentication["host"];
$options = $mysqlAuthentication;
}
if ($this->databaseType == 'mySql' || $this->databaseType == 'both') {
$this->mysqlConnection = @mysql_connect($host, $options["username"], $options["password"]);
}
if (isset($this->mysqlConnection)) {
@mysql_set_charset("utf8");
@mysql_select_db($options["database"], $this->mysqlConnection);
}
if (isset($sqlserverAuthentication)) {
$host = $sqlserverAuthentication["host"];
$options = array("Database" => $sqlserverAuthentication["database"], "CharacterSet" => "UTF-8", "UID" => $sqlserverAuthentication["username"], "PWD" => $sqlserverAuthentication["password"]);
}
if ($this->databaseType == 'sqlServer' || $this->databaseType == 'both') {
$this->sqlserverConnection = sqlsrv_connect($host, $options);
}
}
示例5: save3
public function save3()
{
//获取数据库主机
$host = $_POST['host'];
//获取用户帐号
$user = $_POST['user'];
//获取用户密码
$pass = $_POST['pass'];
//获取数据库名
$name = $_POST['name'];
//获取字段前缀
$prefix = $_POST['prefix'];
$str = "<?php" . "\r\n";
$str .= " define('Sql_type', 'mysql'); //数据库类型" . "\r\n\r\n";
$str .= " define('Sql_host', '{$host}'); //服务器地址" . "\r\n\r\n";
$str .= " define('Sql_name', '{$name}'); //数据库名 " . "\r\n\r\n";
$str .= " define('Sql_user', '{$user}'); //用户名" . "\r\n\r\n";
$str .= " define('Sql_pwd', '{$pass}'); //密码" . "\r\n\r\n";
$str .= " define('Sql_port', '3306'); //端口" . "\r\n\r\n";
$str .= " define('Sql_prefix', '{$prefix}'); //数据库表前缀" . "\r\n\r\n";
$str .= " define('Sql_charset', 'utf8'); //数据库编码默认采用utf8";
file_put_contents(APP_PATH . 'Lib/tm_db.php', $str);
$lnk = @mysql_connect($host, $user, $pass);
mysql_set_charset('utf8');
mysql_query("CREATE DATABASE {$name}");
mysql_query("USE {$name}");
$arr = file_get_contents(APP_PATH . '/Lib/tongmeng.sql');
$res = explode(';', $arr);
foreach ($res as $Res) {
$Sql = $Res . ';';
mysql_query($Sql);
}
$this->display('temp_4');
}
示例6: connect
function connect()
{
$this->_action = 'connect';
if (false === ($this->_link = @mysql_connect($this->_config['host'], $this->_config['user'], $this->_config['pass']))) {
$this->_throwException();
}
$this->_action = 'select database';
if (false === @mysql_select_db($this->_config['path'], $this->_link)) {
$this->_throwException();
}
if (isset($this->_config['params']['charset'])) {
$this->_action = 'set charset';
$success = false;
if (function_exists('mysql_set_charset')) {
// MySQL 5.0.7 and PHP 5.2.3
$success = @mysql_set_charset($this->_config['params']['charset'], $this->_link);
} else {
$success = @mysql_query('SET NAMES "' . $this->_config['params']['charset'] . '"', $this->_link);
}
if (!$success) {
$this->_throwException();
}
}
return $this;
}
示例7: connect
/**
* 连接数据库
* @return resource
*/
function connect()
{
$link = mysql_connect(DB_HOST, DB_USER, DB_PWD) or die("数据库连接失败Error:" . mysql_errno() . ":" . mysql_error());
mysql_set_charset(DB_CHARSET);
mysql_select_db(DB_DBNAME) or die("指定数据库打开失败");
return $link;
}
示例8: mcm_open_db
function mcm_open_db()
{
global $mcm;
mysql_connect($mcm['db_server'], $mcm['db_username'], $mcm['db_password']) or die("Unable to connect to database server.\n");
mysql_select_db($mcm['db_database']) or die("Unable to open database.\n");
mysql_set_charset('utf8');
}
示例9: connect
public function connect($host = '', $user = '', $pass = '', $dbname = '', $port = '3066')
{
$this->dbname = $dbname;
if (!$this->con) {
$myconn = @mysql_connect($host . ':' . $port, $user, $pass);
// mysql_connect() with variables defined at the start of Database class
if ($myconn) {
mysql_set_charset('utf8', $myconn);
$this->mysql_link = $myconn;
$seldb = @mysql_select_db($this->dbname, $myconn);
// Credentials have been pass through mysql_connect() now select the database
if ($seldb) {
$this->con = true;
return true;
// Connection has been made return TRUE
} else {
array_push($this->result, mysql_error($this->mysql_link));
return false;
// Problem selecting database return FALSE
}
} else {
array_push($this->result, 'Something unexpected has gone wrong');
return false;
// Problem connecting return FALSE
}
} else {
return true;
// Connection has already been made return TRUE
}
}
示例10: connect
/**
* Created by PhpStorm.
* User: Administrator
* Date: 16-1-19
* Time: 下午9:54
*/
function connect()
{
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('数据库连接失败!');
mysql_set_charset(DB_CHARSET);
mysql_select_db(DB_DBNAME) or die('指定数据库打开失败');
return $link;
}
示例11: db_connect
function db_connect($dbhost, $dbname, $dbuser, $dbpass)
{
global $DB_DIE_ON_FAIL, $DB_DEBUG, $CFG;
if (!($dbh = mysql_connect($dbhost, $dbuser, $dbpass))) {
if ($DB_DEBUG) {
echo "<h2>Can't connect to {$dbhost} as {$dbuser}</h2>";
echo "<p><b>MySQL Error</b>: ", mysql_error();
} else {
echo "<h2>Database error encountered</h2>";
}
if ($DB_DIE_ON_FAIL) {
echo "<p>This script cannot continue, terminating.";
echo "<a href=\"./\">Click here</a> to return to the homepage.";
die;
}
}
if (!$CFG->dont_select_db) {
if (!mysql_select_db($dbname)) {
if ($DB_DEBUG) {
echo "<h2>Can't select database {$dbname}</h2>";
echo "<p><b>MySQL Error</b>: ", mysql_error();
} else {
echo "<h2>Database error encountered</h2>";
db_error_mail("{$_SERVER['HTTP_HOST']} DB Select Failed", "Page: {$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
}
if ($DB_DIE_ON_FAIL) {
echo "<p>This script cannot continue, terminating.";
echo "<a href=\"./\">Click here</a> to return to the homepage.";
die;
}
}
}
mysql_set_charset('utf8');
return $dbh;
}
示例12: conectar
function conectar()
{
$li = mysql_connect("localhost", "artes_cotizacion", "Cotizaciones_1209");
mysql_set_charset('utf8');
mysql_select_db("artes01_Cotizaciones", $li) or die("Conexión no hecha");
return $li;
}
示例13: connecter
/**
* Etablit la connexion à la base de données
* @param array $aErreurs Le tableau contenant les messages d'erreurs rencontrées
*/
function connecter(&$aErreurs)
{
// Connexion
$this->link = @mysql_connect($this->host, $this->login, $this->password);
mysql_select_db($this->database);
mysql_set_charset('utf8', $this->link);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
// En cas d'erreur
if (!$this->link) {
ajouterErreurDansTableau("Impossible de se connecter à la base de données !", $aErreurs);
if (MODE_DEBUG) {
ajouterErreurDansTableau(' -> ' . mysql_error(), $aErreurs);
}
return false;
}
// Sélection de la base de données
if (!@mysql_select_db($this->database, $this->link)) {
ajouterErreurDansTableau("Impossible de sélectionner la base '" . BD_BASE . "' !", $aErreurs);
if (MODE_DEBUG) {
ajouterErreurDansTableau(' -> ' . mysql_error(), $aErreurs);
}
return false;
}
return true;
}
示例14: db_conn
function db_conn()
{
require __DIR__ . "/../config/config.php";
$connect = mysql_connect($host, $user, $pass) or die("Ошибка соединения: " . mysql_error());
mysql_set_charset('utf8', $connect);
mysql_select_db($db_name);
}
示例15: connect
/**
* Connect to database
* @return resource
*/
function connect()
{
$link = mysql_connect(HOST, USER, PWD) or die("Error:" . mysql_errno() . ":" . mysql_error());
mysql_set_charset(DB_CHARSET);
mysql_select_db(DATABASE) or die("Connect MySQL failed!");
return $link;
}