Please help (PHP / MySQL / Character encoding)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

OKay folks, got a few issues that have me puzzled. Trying to improve my
routines for adding slashes and what not into statements so they can be put
into SQL etc.

Anyway, At the moment I use PHP to construct a query, for example:

UPDATE test SET entry='\"123\"' WHERE id='1'

If I submit this query via phpMyAdmin the following goes in the database:


However, if I submit the query via PHP (on the next line) using
mysql_query() the following goes into the database

"123"£      (note the A circumflex before the pound sign)

Where is the character coming from? There are oher oddities, but they are
probably related so we can deal with one at a time.

The MySQL table did have collation latin1_swedish_ci Swedish, I've just
changed to latin1_bin ...

It is something to do with a MySQL or PHP setting, I'm sure of that

Anyone any ideas please?


Re: Please help (PHP / MySQL / Character encoding)

Quoted text here. Click to load it

Anyone :o(

Re: Please help (PHP / MySQL / Character encoding)

Aaron wrote:

Quoted text here. Click to load it

Character encoding issues (i.e. ISO-8859 vs Unicode) most likely,
rather than what you've typed into the source.

Pick an encoding, any encoding, then use it. Use it _throughout_ the
system, consistently and correctly labelled. You can probably make
almost any encoding work, but you need to use it correctly (i.e. not
mix and match carelessly with others, or with mis-labelled encodings)

As a starting point, personally I'd suggest UTF-8 for everything. This
works, and it works for all international encodings without having to
swap anything around (i.e. it will do both Arabic and Norwegian

Re: Please help (PHP / MySQL / Character encoding)

Quoted text here. Click to load it

OK, thanks for that

If I choose a character set, and make my database, table and all rows into
that encoding will that be enough. For some reason I get the impression
something needs to be changed in php.ini


What is strange is that it works in phpMyAdmin - which is obviously PHP as
well, so perhaps I'm just missing setting teh encoding in PHP or something?

Thanks mate

Site Timeline