/// BANGBOO BLOG ///

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

May 24, 2007

UTF-8

HTML出力、PHP、MySQL、全部UTF-8。その時、??と文字化けが起こったぁぁ。(ウルルン)

//mySQLの文字コード
照合順序 : utf8_general_ci

//mysqlクライアント。コマンドラインからチェック
mysql> SHOW VARIABLES LIKE 'char%';
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |

//phpソースコード・文字コード設定
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

//phpソースコード・PHP内部文字コードとクエリ文字コード設定
<?php //charactor code for php internal
mb_language("uni");
mb_internal_encoding("utf-8");
mb_http_input("auto");
mb_http_output("utf-8");
// database connection
if (!mysql_connect("localhost", "id", "pswd"))
{
     die("Couldn't connect to MySQL");
}
if (!mysql_select_db("dbname"))
{
    die("Couldn't connect to the database");
}
//charactor code for query
$sql = mysql_query("SET NAMES utf8");
$result = mysql_query($sql);
?>

Set Names文のクエリ発行がミソ。

twitter
Hatena
Google Buzz
newsing
Yahoo!
Buzzurl
Technorati
del.icio.us
Choix
Iza!
Livedoor Clip
Facebook
Evernote
 

Posted by funa : 10:41 PM | Web | Comment (0) | Trackback (0)


PhotoGallery


TWITTER
Search

Mobile
QR for cellphone  QR for smart phone
For mobile click here
For smart phone click here
Popular Page
Category
Recent Entry
Trackback
Comment
Archive
<     February 2012     >
Sun Mon Tue Wed Thi Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29
Link