downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mysqli::set_local_infile_default> <mysqli::send_query
[edit] Last updated: Fri, 10 Feb 2012

view this page in

mysqli::set_charset

mysqli_set_charset

(PHP 5 >= 5.0.5)

mysqli::set_charset -- mysqli_set_charsetクライアントのデフォルト文字セットを設定する

説明

オブジェクト指向型

bool mysqli::set_charset ( string $charset )

手続き型

bool mysqli_set_charset ( mysqli $link , string $charset )

データベースサーバとのデータの送受信に使用する、 デフォルトの文字セットを設定します。

パラメータ

link

手続き型のみ: mysqli_connect() あるいは mysqli_init() が返すリンク ID。

charset

デフォルトとして設定する文字セット。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

注意

注意:

Windows プラットフォームでこの関数を使用するには、MySQL クライアント ライブラリのバージョン 4.1.11 以降(MySQL 5.0 の場合は 5.0.6 以降) が必要です。

注意:

文字セットを変更するにはこの方法を使うことを推奨します。 mysqli::query()SET NAMES .. を実行する方法はお勧めできません。

例1 mysqli::set_charset() の例

オブジェクト指向型

<?php
$mysqli 
= new mysqli("localhost""my_user""my_password""test");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

/* 文字セットを utf8 に変更します */
if (!$mysqli->set_charset("utf8")) {
    
printf("Error loading character set utf8: %s\n"$mysqli->error);
} else {
    
printf("Current character set: %s\n"$mysqli->character_set_name());
}

$mysqli->close();
?>

手続き型

<?php
$link 
mysqli_connect('localhost''my_user''my_password''test');

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

/* 文字セットを utf8 に変更します */
if (!mysqli_set_charset($link"utf8")) {
    
printf("Error loading character set utf8: %s\n"mysqli_error($link));
} else {
    
printf("Current character set: %s\n"mysqli_character_set_name($link));
}

mysqli_close($link);
?>

上の例の出力は以下となります。

Current character set: utf8

参考



add a note add a note User Contributed Notes mysqli::set_charset
coder at punkass dot com 12-Apr-2006 11:13
On windows, with "stock" PHP 5.1.2, there is no set_charset function at all. One may have to replace php_mysqli.dll, and libmysql.dll with proper versions, which provided by MySQL at http://dev.mysql.com/downloads/connector/php/

 
show source | credits | stats | sitemap | contact | advertising | mirror sites