Categories: "Full Stack Dev & Design"

Another lousy PHP/MySQL /charset issue...

We had this quite interesting situation at work today: I export an UTF-8 MySQL database into an UTF_8 SQL file. I *binary* FTP the file over to him. He plays the SQL in PHPmyAdmin all configured for UTF-8. He then checks the data in PHPmyAdmin: special chars display right under an UTF-8 page encoding. He checks under the command line: the DB contents seem to be UTF-8 encoded too...

Now he goes to our app, pulls out some data... and gets a special chars mess... although the html page is displayed as UTF-8. If we force the display to Latin-1, the special chars display correctly again.

The reason for this is that there is actuallly a charset translation taking place between the mysql client (which is PHP here) and the mysql server.

We found we could fix this by editing my.cnf and specifying the following:

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8

...instead of the latin-1 he had there for some obscure reason.

However, there must be a more explicit way to have PHP retrieve the mysql data as UTF-8, even though we could not find that in mysql_connect() or somethig alike.

Guess, we'll have to investigate the PhpMyAdmin code and see how those guys do it. Btw, this reminds me of a conference by Rasmus Lerdorf where he said the code for PhpMyAdmin was pretty clean and should be studied. Yep, we definitely gotta do that! ;)

Using PHP 4.3.8 with MySQL 4.1

Running an app under PHP 4.3.8 and trying to connect to a MySQL 4.1 database can be pretty frustrating. By default it gives you a message like this:

"Client does not support authentication protocol requested by server; consider upgrading MySQL client".

The problem is that by default PHP's MySQL module is compiled with an older MySQL client library. MySQL has a manual page about this.

I use the OLD_PASSWORD method. I connect to MySQL under root with MySQL Query Browser and I issue the following command:

set password for 'demouser' = old_password('demopass');

Offshoring/outsourcing software development

This thread in Ask Joel is the most interesting discussion I've ever read abut offshoring/outsourcing software development!

It's getting incredibly long though, so it's really hard to read through. But the first 25 comments are definitely worth reading.

My personal take on the subject is roughly this: I believe software is art more than science. I think the best approach to make it look like engineering is something along the Unified Process - that's what the IT world has learned the hard way for the last 30 years! One golden rule of UP is to have the users and the coders communicating, to have them understand each other's constraints...

This doesn't mean I think nothing can be outsourced, but you certainly cannot carelessly offshore a whole IT department to a place with a radically different culture and expect that communicating with specs will "just work"! :|

If offshoring software development is ever going to succeed we'll need a whole new set of skills and tools (internet being one of them) to master it, and we're not even close! However, I think the experience of open source software projects developped by an international community are an interesting experience to this.

I would probably elaborate on this if I wasn't this busy reading the thread at Joel's right now! :>>

Coder to Developer

From Joel's foreword to Mike Gunderloy's "Coder to Developer":

When I got out of the army, I headed off to college and got a degree in Computer Science. Now I really knew everything. I knew more than everything, because I had learned a bunch of computer-scientific junk about linear algebra and NP completeness and frigging lambda calculus which was obviously useless, so I thought they must have run out of useful things to teach us and were scraping the bottom of the barrel.


Nope. At my first job I noticed how many things there are that many Computer Science departments are too snooty to actually teach you. Things like software teamwork. Practical advice about user interface design. Professional tools like source code control, bug tracking databases, debuggers and profilers. Business things. Computer Science departments in the most prestigious institutions just won’t teach you this stuff because they consider it “vocational,” not academic; the kind of thing that high school dropouts learn at the local technical institute so they can have a career as an auto mechanic, or an air-conditioner repairman, or a (holding nose between thumb and forefinger) “software developer.”


[...]


There’s something weird about software development, some mystical quality, that makes all kinds of people think they know how to do it. I’ve worked at dotcom-type companies full of liberal arts majors with no software experience or training who nevertheless were convinced that they knew how to manage software teams and design user interfaces. This is weird, because nobody thinks they know how to remove a burst appendix, or rebuild a car engine, unless they actually know how to do it, but for some reason there are all these people floating around who think they know everything there is to know about software development.




I bet this sounds familiar to many of you if you've been in the field for a little while... :>>

PHP Output buffering and ob_handlers

PHP has some nice features to do output buffering. You just call ob_start() and anything you output (except headers) does not actually get set back to the webserver (and thus the browser) until you decide it. As the manual puts it "This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data."

One particular use of this feature is to pass an "ob_handler" callback function as an argument to ob_start(). This is supposed to let you do "kewl" post-processing operations like: gzip compression, adding an ETag, adding content-length of your whole output.

Crap!

There are only two situations where ob_handlers are useful:

  • When your webserver can't take care of this for you. But you know, you should really consider switching to Apache, which already has modules to handle all that, and even better: unlike PHP ob_handlers, it can do gzip compression progressively without waiting for the whole page to have generated! :crazy:
  • When you are in desperate need for marketing arguments to write a book on ~` Advanced PHP '~ ! >:XX