du5407 2012-11-13 17:44
浏览 76

数据库迁移期间的UTF-8编码错误

I keep getting the silly invalid byte sequence for encoding "UTF8": 0x96 error or whatever it is. Now I've identified it as a problem with my server space.

The thing is I migrated from a very similar database which was also UTF-8. I test out my PHP scripts on the first database and they work but on the one I require they do not. It must be a problem with encoding but I'm not sure what.

My PHP queries are failing on the new database and producing that error.

PHP:

$name = $_POST["name"];
$type = $_POST["type"];
$contact = $_POST["contact"];
$address = $_POST["address"];
$postcode = $_POST["postcode"];
$phone = $_POST["phone"];
$description = $_POST["description"];
$location = $_POST["location"];

$conn = pg_connect(/*DATABASE CONNECTION DETAILS*/);

$res = pg_query("INSERT INTO address (organisation_type, contact_name, address, postcode, phone_number, description, location_to_town, organisation_name) VALUES ('$type', '$contact', '$address', '$postcode', '$phone', '$description', '$location', '$name')");

 pg_close($conn);

I mean that is a simple PHP write to database function and the only oddity is that of one UTF-8 database working and the other not. Is there any way I can compare the server/change the configurations of my PostGreSQL server at the command line?

Thanks any information would be much appreciated. Tearing my hair out over this!

  • 写回答

1条回答 默认 最新

  • douteng5673 2012-11-13 18:24
    关注

    The error message names 0x96, which does not look like UTF-8 but rather a dash in some 8 bit charset. Make sure that you are posting UTF-8, by setting the correct meta header in your HTML:

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    

    Or sending the charset with a content type HTTP header on the PHP side:

    header('Content-Type: text/html; charset=utf-8');
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向