9月 202010
 

query(‘SET NAMES utf8’); を実行する。
SET NAME は、クライアントから送信されるSQLステートメントの文字セットを指定。
SET CHARACTER_SET は、クライアントから送信される SQL ステートメントの文字セットと、サーバーからクライアントに返される文字セットを指定。
try{
   $pdo=new PDO( ‘mysql:host=localhost ; dbname= testDB , user , pass );
   //文字セット
   $pdo->query(‘SET NAMES utf8’);
   //sql準備
   $stmt=$pdo->prepare(“select * from test”,array());
   //実行
   $stmt->execute();
   //結果を一行ずつ取得
   while($row=$stmt->fetch()){
      $data=$row[0].”\t”.$row[1].”\n”;
      print $data;
   }
   $stmt=null;
}catch(PDOException $e){
   print $e->getMessage();
}

よく読まれている記事

この記事を読んだ人は次の記事も読んでいます:

このエントリーをはてなブックマークに追加
はてなブックマーク - mysql 文字化けを防ぐ エンコード
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]
[`evernote` not found]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)