buy linux on cd and dvd

PHP number_format() always returns 0PHP number_format() always returns 0

Posted September 22nd, 2007 in PHP (Updated September 28th, 2007)

After I inadvertently upgraded from openSUSE 10.2 to openSUSE 10.3RC1, I discovered that phpMyAdmin was showing all my database tables with 0 records in them. When I browsed the tables or ran a query that would return records then it would return them as expected. The screenshot below shows a test database. You can see it shows 0 in the "Records" column, although it should show 3349 for the first table and 2 for the second.

phpmyadmin showing 0 records

At the same time, I was working with a client's application and there is a reporting function which shows the number of times particular actions have been taken. Just as with phpMyAdmin, this report was showing 0 for the totals. I checked the production version of this application and it was showing the data correctly, so I reloaded my local version of this particular database from a dump I made of the production one. However I was still having the same issue in both my application and in phpMyAdmin.

I began to wonder if my database tables had become corrupted with the update to MySQL, so I dumped all the databases into a SQL file, cleared out the binary database files and got MySQL to recreate the default database tables. After loading the databases back into MySQL I took another look in phpMyAdmin and it was still showing 0 in the records column.

I modified the code of the client's application to output the data returned from the database using print_r() to see exactly what was being returned and the counts were correct, but they were still being displayed as a 0 in the report itself. I noticed that where it was output in the report the PHP number_format() function was being used. I changed the code to not use this function and the report now displayed correctly.

I then had a search in the phpMyAdmin code and discovered that the record count is also displayed using the number_format() function. So it would appear there is a bug in this function, either in PHP itself, or openSUSE 10.3's version of PHP.

To put it simply,

echo number_format(10);

should output 10, but each time, and for any number at all, always outputs 0.

I have filed a bug report in the Novell bugzilla database so we'll see what happens.

Update 28 September 2007

Naturally the chap looking at my bug report was unable to replicate my issue. I did an update today which update both the kernel from 2.6.22.5-18-default to 2.6.22.5-29-default and PHP from 5.2.4-7 to 5.2.4-10 and now the problem has gone away. Yay!

Yahoo! Personals Canada Yahoo! Games