定义

mysqli_set_charset()函数设置默认字符集。

 

语法

PHP mysqli_set_charset()函数具有以下语法。

mysqli_set_charset(connection,charset);

 

参数

参数 是否必须 描述
connection 需要。 MySQL连接使用
charset 需要。 默认字符集

 

返回值

成功时返回TRUE。失败时为FALSE。

 

实例

设置默认字符集

<?php
    //  http://www.manongjc.com/article/1695.html
    //  作者:码农教程
    $con=mysqli_connect(\"localhost\",\"my_user\",\"my_password\",\"my_db\");

    if (mysqli_connect_errno($con)){
       echo \"Failed to connect to MySQL: \" . mysqli_connect_error();
    }
    
    // Change character set to utf8
    mysqli_set_charset($con,\"utf8\");
    
    mysqli_close($con);
?>
收藏 打印