duan5731 2012-03-30 09:52
浏览 47

too long

I have a small php-snippet that, when called through AJAX, returns some entries from a database - standard stuff, really. However, I recently realised there's a problem:

There are two scenarios possible:

  • The snippet is called in such a fashion that something is either created or updated in the database
  • The snippet is called such that information is returned, in terms of HTML echoed by the php

Now, when asking the snippet to update something, one must supply a string. If this string contains some odd character, say σ, things break a tad:

  • Somewhere between the Javascript that sends a request and the database receives the query, the sigma becomes unrecognisable. I imagine this lies in that the URI is a URI instead of the fancy IRI. If so, how do I get around this? If it helps, the sigma becomes σ.

  • For testing purposes, I tried to enter the sigma directly through the database interface - that works fine. The sigma looks as it should, but only from within the phpmyadmin GUI! Once I request this working sigma from the php-snippet, I receive ?.

I can understand how it's problematic to push the sigma through the URI, but I don't quite understand why php cannot properly handle the sigma requested in the second bullet point - I could have sworn php supports utf8_general_ci, which is the collation of the database.

So, for my questions:

  • How shall I encode odd characters like σ so that it isn't mutilated when encoded for UTI purposes?
  • How do I make it so that php doesn't mangle the sigma to a question mark?

Note: I am generally confused as to what terms to use in regard to the URL/URI/IRI et cetera - I am not necessarily educated in the field. Please excuse any butchering of the abbreviations.

Addendum: The data Javascript passes to the php-snippet to the pushed into the database is encoded with encodeURIComponent().


Update: I have narrowed in on the problem in the following fashion: the Javascript passes the correct characters to the php, but the php itself passes incorrect characters to the database. Since php itself should be able to handle the characters, I have the following question: is it possible php fails to maintain the encoding within the mysql_query()?

Further information: the incorrectly passed σ, which is recorded as such in the database, will maintain this form when I ask for it to be returned back to php.

Additionally, since php fetches the string from the URL using $_GET[], is it possible that this function disturbs the encoding?



Final addition: It is the php file itself that is the problem! When I added echo 'σ';, I got σ in return. It seems to me, then, that my php document is, for some reason, not encoding in utf8, and I don't know how to adjust that…

OK, scratch that, that's all wrong. I have gotten the output of the php, i.e. the HTML, to look right, but even so what the php passes through queries to the database is incorrect. Could the encoding be failing just while querying?

  • 写回答

1条回答 默认 最新

  • douxu3732 2012-03-30 10:05
    关注

    Anyway to shorten up, maybe you could find this useful before you post data via JS to DB, so now try to experiment with inserts and updates..

    encodeURIComponent(your post var)

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?