<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mysql.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.mysql-set-charset.php',
    1 => 'mysql_set_charset',
    2 => '设置客户端的字符集',
  ),
  'up' => 
  array (
    0 => 'ref.mysql.php',
    1 => 'MySQL 函数',
  ),
  'prev' => 
  array (
    0 => 'function.mysql-select-db.php',
    1 => 'mysql_select_db',
  ),
  'next' => 
  array (
    0 => 'function.mysql-stat.php',
    1 => 'mysql_stat',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/mysql/functions/mysql-set-charset.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mysql-set-charset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysql_set_charset</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.3)</p><p class="refpurpose"><span class="refname">mysql_set_charset</span> &mdash; <span class="dc-title">设置客户端的字符集</span></p>

 </div>

 <div id="function.mysql-set-charset-refsynopsisdiv">
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">本扩展自 PHP 5.5.0
起已废弃，并在自 PHP 7.0.0 开始被移除。应使用 <a href="book.mysqli.php" class="link">MySQLi</a>
或 <a href="ref.pdo-mysql.php" class="link">PDO_MySQL</a> 扩展来替换之。参见 <a href="mysqlinfo.api.choosing.php" class="link">MySQL：选择 API</a> 
指南来获取更多信息。用以替代本函数的有：</p>
   <ul class="simplelist">
    <li><span class="function"><a href="mysqli.set-charset.php" class="function">mysqli_set_charset()</a></span></li>
    <li>PDO: 添加 <code class="literal">charset</code> 到连接字符串，比如 <code class="literal">charset=utf8</code></li>
   </ul>
  </div>
 </div>

 <div class="refsect1 description" id="refsect1-function.mysql-set-charset-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mysql_set_charset</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$charset</code></span>, <span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$link_identifier</code><span class="initializer"> = NULL</span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="simpara">
   设置当前连接的默认字符集。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-set-charset-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt><code class="parameter">charset</code></dt>
    <dd>
     <span class="simpara">
      一个有效的字符集名称。
     </span>
    </dd>
   
   <dt>
<code class="parameter">link_identifier</code></dt><dd><p class="para">MySQL
连接。如不指定连接标识，则使用由 <span class="function"><a href="function.mysql-connect.php" class="function">mysql_connect()</a></span>
最近打开的连接。如果没有找到该连接，会尝试不带参数调用
<span class="function"><a href="function.mysql-connect.php" class="function">mysql_connect()</a></span>
来创建。如没有找到连接或无法建立连接，则会生成
<strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> 级别的错误。</p></dd>

  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-set-charset-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="simpara">
   成功时返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-set-charset-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    本函数需要 MySQL 5.0.7 或更高版本。
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    这是改变字符集的最佳方式。不推荐您使用
    <span class="function"><a href="function.mysql-query.php" class="function">mysql_query()</a></span> 来设置 (比如 <code class="literal">SET NAMES utf8</code>)。
    更多信息参见 <a href="mysqlinfo.concepts.charset.php" class="link">MySQL character set concepts</a>
    一节。
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-set-charset-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><a href="mysqlinfo.concepts.charset.php" class="link">Setting character sets in MySQL</a></li>
   <li><a href="http://dev.mysql.com/doc/mysql/en/charset-charsets.html" class="link external">&raquo;&nbsp;List of character sets that MySQL supports</a></li>
   <li><span class="function"><a href="function.mysql-client-encoding.php" class="function" rel="rdfs-seeAlso">mysql_client_encoding()</a> - 返回字符集的名称</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>