post php mysql utf-8 and russian

post php mysql utf-8 and russian

I have problem with Russian after jquery post using

so here we go: 3 files

INDEX.PHP

<?php

 

header("Content-Type: text/html; charset=utf-8");

include_once 'CDDB.php';

include_once 'db.php';

 

 

?>

 

<!DOCTYPE html>

<html>

 

<head>

 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>DEFAULT 112</title>

 

<!-- jquery -->

<link href="jquery/css/overcast/jquery-ui-1.8.22.custom.css" type="text/css" rel="stylesheet" />

<script src="jquery/js/jquery-1.7.2.min.js" type="text/javascript"></script>

<script src="jquery/js/jquery-ui-1.8.22.custom.min.js" type="text/javascript"></script>

 

<script type="text/javascript">

$(function(){

$('.JQButton').button();

$('#Test').click(function(){

$.post('db.php', function(data){

$('#DB').html(data);

 

});

});

});

</script>

 

</head>

 

<body>

 

<div id=main>

<div id=Test class=JQButton>Test</div>

<div id=DB></div>

</div>

 

</body>

 

</html>

 

CDDB.php

 

<?php

 

$db = new PDO('mysql:host=localhost;charset=utf8', 'root', '');

 

$query = $db->prepare('DROP DATABASE `default_db`');

 

$query->execute();

$query = $db->prepare('CREATE DATABASE `default_db` CHARACTER SET = utf8 COLLATE = utf8_general_ci');

 

$query->execute();

$db = new PDO('mysql:host=localhost;dbname=default_db;charset=utf8', 'root', '');

 

$query = $db->prepare('SET NAMES utf-8');

 

$query->execute();

$query = $db->prepare('CREATE TABLE `default_table` (

 

 

`uid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

`name` VARCHAR(100) NOT NULL,

`birth` DATETIME NOT NULL,

`sex` TINYINT NOT NULL,

`position` VARCHAR(100) NOT NULL,

`phone` VARCHAR(10) NOT NULL

)

 

ENGINE = myisam CHARACTER SET = utf8 COLLATE = utf8_general_ci');

 

$query->execute();

$query = $db->prepare('INSERT INTO `default_table` (

 

 

`name`, `birth`, `sex`, `position`, `phone`

)

VALUES (

"Вася Пупкин", "1985-01-01 00:00:00", "1", "Дворник", "999"

 

)');

 

$query->execute();

?>

DB.php

<?php

 

$db = new PDO('mysql:host=localhost;dbname=default_db;charset=utf8', 'root', '');

 

$query = $db->prepare('SELECT * FROM `default_table` ORDER BY `uid`');

 

$query->execute();

while($arr = $query->fetch())

 

{

$PDO_arrarr[] = $arr;

}

print_r($PDO_arrarr);

echo '<br><br>name: '.$PDO_arrarr[0][name].'<br><br>';

echo '<br><br>name: '.iconv("utf-8", "windows-1251", $PDO_arrarr[0][name]).'<br><br>';

 

 

?>

LAYOUT:

Array ( [0] => Array ( [uid] => 1 [0] => 1 [name] => Вася Пупкин [1] => Вася Пупкин [birth] => 1985-01-01 00:00:00 [2] => 1985-01-01 00:00:00 [sex] => 1 [3] => 1 [position] => Дворник [4] => Дворник [phone] => 999 [5] => 999 ) )

name: Вася Пупкин



name: ���� ������

DEFAULT 112







Test
Array ( [0] => Array ( [uid] => 1 [0] => 1 [name] => Вася Пупкин [1] => Вася Пупкин [birth] => 1985-01-01 00:00:00 [2] => 1985-01-01 00:00:00 [sex] => 1 [3] => 1 [position] => Дворник [4] => Дворник [phone] => 999 [5] => 999 ) )

name: Вася Пупкин



name: Вася Пупкин