Re: implode() in MDB_QueryTool - decimal-point -> comma

From: Date: Mon, 15 May 2006 13:53:37 +0000
Subject: Re: implode() in MDB_QueryTool - decimal-point -> comma
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24079@lists.php.net to get a copy of this message
Am Sonntag, 14. Mai 2006 23:14 schrieb Justin Patrin: > On 5/14/06, Lukas Ruetz <lukas.ruetz@gmx.at> wrote: > > Am Sonntag, 14. Mai 2006 20:46 schrieb Justin Patrin: > > > On 5/14/06, Lukas Ruetz <lukas.ruetz@gmx.at> wrote: > > > > Am Sonntag, 14. Mai 2006 19:25 schrieben Sie: > > > > > Lukas Ruetz wrote: > > > > > > I'm not sure if this has anything to do with QueryTool but in > > > > > > every case there is something wrong with implode() > > > > > > > > > > > > The symptom is that I can't insert floats because the > > > > > > decimal-points become commas in MDB/QueryTool/Query.php -> add(). > > > > > > var_dump shows me that my floats in the array have the correct > > > > > > type, but if the array is processed by implode() the > > > > > > decimal-points become commas in the resulting string. > > > > > > > > > > > > The strange thing is that implode(', ', $newData) does this > > > > > > incorrect transforming inside Query.php but _not_ if i test this > > > > > > in a simple script where implode() leaves the decimal-point > > > > > > untouched. > > > > > > > > > > A reproducing script would be helpful, > > > > > since I can't see how that implode() call > > > > > would break your script. > > > > > > > > > > Regards, > > > > > > > > I wanted to write a simple script that reproduces the error, but like > > > > I said before, in a simple script the error is gone. Finally I could > > > > see that the error occures only if I use the DB-code inside > > > > Flexy-page-classes. Although QueryTool is influenced by "something" > > > > it isn't the cause. This is a really strange error - I will search on > > > > tomorrow. > > > > > > "Something" is changing the locale of your numbers. I suggest checking > > > your "float" in various parts of your script. Perhaps it's Flexy, > > > perhaps it's a function that QueryTool calls (it's not the implode, > > > look elsewhere), and perhaps it's something else your script is doing. > > > > > > -- > > > Justin Patrin > > > > Hi! > > > > Of course it's the locale *argh* - I set the locale in > > Flexy/Translation2. I thought, because the float is correct in the array > > it has to be converted the right way. But implode() returns floats > > regarding to the current locale. So if I switch to english it's working, > > but if I use my german locale, implode() will convert the decimal-point > > "corretly" to our decimal-comma. But this is useless for the SQL-syntax. > > > > Can I change this behaviour of PHP in combination with a western-europe > > locale? Otherwise the QueryTool has to deal with float values in a > > different way. > > http://us2.php.net/implode > > That function has nothing to do with locales. > > -- > Justin Patrin Hi Justin and Lorenzo! implode() converts each value to a string and thats the point where the locale is importand. Finally when I looked at setlocale() I found what I was searching for - a setting for the decimal-char (locale). It was too easy .. <?php $arr = array( "myfloat" => 0.01, ); setlocale( LC_ALL, 'en_US' ); echo '<br/>implode (en) '.implode(', ',$arr); setlocale( LC_ALL, 'de_DE' ); echo '<br/>implode (de) '.implode(', ',$arr); setlocale( LC_NUMERIC, 'en_US' ); echo '<br/>implode (de2) '.implode(', ',$arr); ?> @Lorenzo - so a standard western-europe locale (without setting the LC_NUMERIC option) stops QueryTool from working correctly. Maybe this could be addressed in a future release. thanks luk

« previous php.pear.general (#24079) next »