drnf593779 2015-11-19 02:45
浏览 53
已采纳

SQL查询在PHP中返回空结果 - 同一查询在PHPMyAdmin中返回结果

I have a webpage which executes several MySQL queries using PHP and returns the results. One query contains a special character - Î - as in ...WHERE region="Île-de-France"... When executed by PHP this query executes successfully but returns an empty result set, when it should return a result. In an attempt to debug I used echo on the $sql variable holding the sql query (just before it is executed) and copied the result into PHPMyAdmin. Here the same query returned the result I was expecting.

Why is this query returning nothing when executed by PHP?

Things I have tried based on information I didn't particularly understand:

I used $sql=$db->real_escape_string($sql) before executing the query. This changed the relevant portion of $sql to ...WHERE region=\"Île-de-France\"... and resulted in an error upon execution of the query.

I also tried if($state){$sql=$sql." AND state ='".$db->real_escape_string($state)."'";}. The query now executed successfully but yielded no results.

  • 写回答

1条回答 默认 最新

  • douhuan1908 2015-11-19 23:41
    关注

    Sounds like the database connection you are using has a different character encoding, I would check the default encoding and or try setting it explicitly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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