PHP mysqli_set_charset() 函数
PHP mysqli_set_charset() 函数
设置默认客户端字符集:
<?php
// 假定数据库用户名:root,密码:123456,数据库:RUNOOB
$con=mysqli_connect("localhost","root","123456","RUNOOB");
if (mysqli_connect_errno($con))
{
echo "连接 MySQL 失败: " . mysqli_connect_error();
}
// 修改数据库连接字符集为 utf8
mysqli_set_charset($con,"utf8");
mysqli_close($con);
?>
这样的操作在针对中文字符非常有用,很多数据库查询乱码的情况都是字符集的问题。
定义和用法
mysqli_set_charset() 函数规定当与数据库服务器进行数据传送时要使用的默认字符集。
注释:在 Windows 平台上使用该函数,您需要 MySQL 客户端库 4.1.11 或以上版本(MySQL 5.0 需要 5.0.6 或以上版本)。
语法
mysqli_set_charset(connection,charset);
| 参数 | 描述 |
|---|---|
| connection | 必需。规定要使用的 MySQL 连接。 |
| charset | 必需。规定默认字符集。 |
技术细节
| 返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
|---|---|
| PHP 版本: | 5.0.5+ |
PHP MySQLi 参考手册 相关文章
- PHP 数组排序
- PHP For 循环
- PHP 包含文件 include 和 require 语句
- PHP 异常处理
- PHP array_diff() 函数
- PHP array_diff_assoc() 函数
- PHP array_filter() 函数
- PHP array_intersect_ukey() 函数
- PHP array_key_last() 函数
- PHP array_multisort() 函数
- PHP array_reduce() 函数
- PHP array_sum() 函数
- PHP array_uintersect_assoc() 函数
- PHP array_unique() 函数
- PHP array_values() 函数
- PHP array_walk() 函数
- PHP arsort() 函数
- PHP 5 Array 函数
- PHP 5 Date/Time 函数
- PHP 杂项 函数


