CodeIgniter Forums
Problem with pound (£) in MySQL AR insert statements - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem with pound (£) in MySQL AR insert statements (/showthread.php?tid=7507)

Pages: 1 2


Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Derek Jones[/eluser]
What's the character set being delivered by the server and web page? Your database table is latin1, an odd choice, IMO, but I suspect you're just criss-crossing character sets. If you have a link to the page with the output, that would be helpful to someone wanting to assist you in confirming or ruling that out.


Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Max_Power[/eluser]
OK.

I've set up a test page at http://maxpower.plus.com.

The output is currently two data columns - opt and value, which are displayed in a for-each loop.

Cheers!

Just adding an input field...


Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Derek Jones[/eluser]
Your server appears to be forcing utf-8 headers - if I set my browser to view that page as utf-8, it displays properly. You could have that disabled, but you'd be better off to convert your database to utf-8 and use utf-8 exclusively throughout your application and site.


Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Max_Power[/eluser]
Thanks for that. I set up this test with UTF-8:

Code:
CREATE TABLE IF NOT EXISTS `test` (
  `opt` varchar(255) NOT NULL,
  `value` varchar(255) NOT NULL,
  PRIMARY KEY  (`opt`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Still doesn't return the GBP symbol correctly...


Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Derek Jones[/eluser]
Yes, but what are your charset and collation settings in your CI db driver?


Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Max_Power[/eluser]
Sorry!

They are in UTF-8 as well:

Code:
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";



Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Derek Jones[/eluser]
I would see if it makes a difference if you enter the data via a utf-8 encoded web page from a form. Say, from phpMyAdmin with utf-8 selected, or CI's deprecated-but-still-exists scaffolding. And for certain, I'd ask the server admin to disable the feature of forcing a character set, and construct proper HTML output including a meta tag defining the correct character set. At it's base, what you have is a simple problem of multiple points not communicating to each other in the same character set, but if your configuration is set properly, CI really isn't involved there.


Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Max_Power[/eluser]
Bang on!

Thanks for your help. In my main app I set the character set to iso-8859-1 probably from copying and pasting some old code.

I was using phpMyAdmin (which was fine) and I double-checked the scaffolding which was also having no problems.

Using utf-8 in my header now and all is well.

Thanks again - you're a star!


Problem with pound (£) in MySQL AR insert statements - El Forum - 01-12-2009

[eluser]Derek Jones[/eluser]
Glad we could help, Max_Power, and welcome to the community!