การแสดงข้อมูลจากฐานข้อมูล เมื่อมีการเปลี่ยน charset ใน แท็ก meta เช่น เปลี่ยนจาก windows-874 เป็น utf-8
เดิม
1 | < meta http-equiv = "Content-Type" content = "text/html; charset=windows-874" /> |
เปลี่ยนเป็น
1 | < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> |
ข้อมูลที่แสดงอาจจะมีการแสดงผลที่ผิดพลาดเกิดขึ้น เช่นข้อความอ่านไม่ออก หรือเป็น ตัวอักษรแปลกๆ เป็นต้น ลองแก้ปัญหาโดยการ set ค่า character set ในขั้นตอนการติดต่อฐานข้อมูล ให้ตรงกับ ค่า charset ใน แท็ก meta ในหน้าเว็บเพจนั้นๆ เช่น ถ้า charset ใน แท็ก meta เป็น utf-8 ก็ให้กำหนดคำสั่ง sql เป็น mysql_query("set character set utf8"); เป็นต้น
ตัวอย่างการใช้งาน
1 2 3 4 5 | <?php $link =mysql_connect( "localhost" , "root" , "123456" ); // เชื่อมต่อ Server mysql_select_db( "example_db" ); // ติดต่อฐานข้อมูล mysql_query( "set character set utf8" ); // กำหนดค่า character set ที่จะใช้แสดงผล ?> |