Development

Do I need a primary key and should it be called id?

While working with databases – especially Mysql – most people seem to ask the same question over and over again when it comes to Primary Keys. Here’s my typical answer to the question(s) above (and more).

Do I need a primary key?

No, you don’t need it, but if you haven’t got one, there’s probably something wrong with your data model. A primary key is the unique key to a row in a table. It can be a single column, but in some cases it can be a combination of two or more columns.

MVC for PHP

With the amazing buzz around RubyonRails, everyone seems to be hooked on the Model-View-Controller (or just MVC) paradigm – and do strive to mindlessly implement the ”Ruby way” into other programming languages without too much reflection and thoughts on how to do it. . Even tough most of the efforts I’ve seen so far seem pretty hopeless; I do believe you could actually do something good with MVC and PHP. Let me try to tell you how. My ”systems thinking” is usually in the ”large professional genre” and it’s an absolute requirement that the PHP code developed is Efficient, Secure and Maintainable. To get a decent shoot at these, we really can’t reuse ideas and ideologies from Java or Ruby into PHP – we must adapt them to the strengths, weaknesses and ”php ways” to get a good result.

QuickSilver

I finally get it. QuickSilver that is. Its an application for the Mac OSX and is the best friend any OSX Power User can have. I’ve downloaded it a couple of times, tried to figure what it was and uninstalled it – but not any more. It’s just great and ought to be build into the OSX. QuickSilver is sort of a power tools basically has made my muse workless today. It’s a power-edition of the Dock and it probably has a ton of undiscovered features I haven’t figured out yet.

Coding style

I usually edit more code others made, than I create new files, and while most of the code is in PHP, there’s a huge difference in the coding style applied by different developers, and some styles are much more annoying than others. I do respect that people are different and that is probably more efficient to allow for some degree of personal style than to try to enforce a single common style. If possible try to make standards where all can agree upon them, and where it isn’t possible, don’t force it too hard (on less pressing issues makes it necessary).

Emptying mysql tables

There are actually two ways to wipe a mysql table either using delete or using truncate – which is better and why? So far my most commonly used form to wipe a table has simple been by using:

DELETE FROM tablename;
which works fine for most cases, but mysql also offers a different method:

TRUNCATE tablename;

Besides the fact that it seems to be faster (even on small tables with few rows) – which in itself is a reason to favour this method - it also has another nice feature, which may be desirable. It resets the AUTO_INCREMENT field if it exists, and let the counter start over from 1.