0
我從this page得到了以下應用程序,以便我可以在MySQL數據庫上測試字符編碼。我創建使用在同一頁上列出的查詢在MySQL數據庫中測試編碼的應用程序未提交到表
CREATE TABLE `texts` (
`id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
`content` TEXT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
數據庫,即:並進入詳細信息連接到我的數據庫,我敢肯定是正確的。然而,由於某種原因,沒有什麼是越來越提交到我的數據庫,當我手動添加一個條目到數據庫中,我得到下面的「輸出測試」以下錯誤:
注意:未定義指數:文本在/ home /..../php/encoding_test.php上 線56
我不知道,如果一些能發現什麼問題可能是什麼?
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
header('Content-Type: text/html; charset=utf-8');
$pdo = new PDO('mysql:dbname=encoding_test;host=localhost', 'user', 'pass',
array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
if (!empty($_POST['text'])) {
$stmt = $pdo->prepare('INSERT INTO `texts` (`text`) VALUES (:text)');
$stmt->execute(array('text' => $_POST['text']));
}
$results = $pdo->query('SELECT * FROM `texts`')->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<title>UTF-8 encoding test</title>
</head>
<body>
<h1>Display test</h1>
<p>
A good day, World!<br>
Schönen Tag, Welt!<br>
Une bonne journée, tout le monde!<br>
يوم جيد، العالم<br>
좋은 일, 세계!<br>
Một ngày tốt lành, thế giới!<br>
こんにちは、世界!<br>
</p>
<h1>Submission test</h1>
<form action="" method="post" accept-charset="utf-8">
<textarea name="text"></textarea>
<input type="submit" value="Submit">
</form>
<?php if (!empty($_POST['text'])) : ?>
<h2>Last received data</h2>
<pre><?php echo htmlspecialchars($_POST['text'], ENT_NOQUOTES, 'UTF-8'); ?></pre>
<?php endif; ?>
<h1>Output test</h1>
<ul>
<?php foreach ($results as $result) : ?>
<li>
<pre><?php echo htmlspecialchars($result['text'], ENT_NOQUOTES, 'UTF-8'); ?></pre>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
謝謝,修復它。 – Nick 2012-08-14 16:11:36