ฉันแค่พยายามแทรกข้อมูล UTF8 ในฐานข้อมูลแล้วดึงข้อมูล แต่มีบางอย่างที่ยุ่งมาก! มันแสดงข้อผิดพลาดอย่างหนึ่งเท่านั้น
นี่คือ และฉันคิดว่าไม่มีอะไรผิดปกติ
ข้อผิดพลาดร้ายแรง: การเรียกไปยังฟังก์ชันสมาชิก fetchAll() บนบูลีน
นี่คือซอร์สโค้ด ฉันค้นหาปัญหานี้แล้ว แต่สิ่งเหล่านี้ใช้ไม่ได้ในสถานการณ์นี้ โปรดอย่าทำเครื่องหมายว่าซ้ำกันเพราะฉันลองมาหมดแล้วแต่ไม่ได้ผล ดังนั้นฉันจึงโพสต์ ขอบคุณล่วงหน้า.
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
header('Content-Type: text/html; charset=utf-8');
$pdo = new PDO('mysql:dbname=ourcms;host=localhost', 'root', '',
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>
tests
ไม่ใช่texts
? และคุณกำลังพยายามแทรกลงในtexts
ด้วยคอลัมน์text
แทนที่จะเป็นtest
? - person Jon   schedule 04.04.2016