您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 恩施分类信息网,免费分类信息发布

php mysqli如何设置编码

2024/3/17 22:47:20发布10次查看
php mysqli设置编码的语法是“mysqli_query($con,'set names utf8');”,该语句表示将编码设置为“utf8”,其中“mysqli_query”函数的参数需要两个。
推荐:《php视频教程》 
先看一段实例代码:
<?phpheader ( "content-type:text/html;charset=utf-8" ); //统一输出编码为utf-8$con = mysqli_connect ( 'localhost', 'root', '' ); //数据库连接if (mysqli_select_db ( $con, 'mytest' )) {echo "数据库ok";} else {echo '数据库错误';} <span style="color:#ff0000;">mysqli_query($con,'set names utf8'); //设置读取数据后的编码</span>$query = "select * from users"; $arr = mysqli_query ( $con, $query );print_r ( mysqli_fetch_array ( $arr ) );mysqli_close ( $con );?>
要点备注:
1.数据库创建时必须指定utf-8编码
2.创建项目后在项目上设定默认编码为utf-8
3.mysqli_query($con,'set names utf8'); 
注意mysqli_query和mysql_query的参数区别:mysql_query(set names 'utf8');的参数只有一个,mysqli的需要两个,否则报错
以上就是php mysqli如何设置编码的详细内容。
恩施分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录