PEAR:DB Database Abstraction Layer

11.08.2005 at 09:31

Nowadays web applications need to be flexible and so it is wise to use a database abstraction layer, so it will be easy to exchange the underlying DBMS. There are quite a few projects out there who provide this functionality, PEAR:DB PEAR:MDB and AdoDB are probably the most popular ones.

While developing this page I took a closer look at PEAR:DB mostly because it is a part of PEAR and therefore available on most systems by default. Furthermore it's API is straight forward and the documentation is usable. Additionally I can recommend reading the excellent Quick Start Guide to Pear DB.

Since PEAR:DB aims to support multiple DBMS they need to make some compromises, for example not all DBMS support something like mysql_insert_id() therefore such a feature has to be emulated. In case of PEAR:DB this is done with sequences.

Of course you could do an ugly hack like this:


However this is DBMS-specific code and the whole point of using a DB abstraction layer is to avoid this kind of thing. Furthermore, you will be screwed if the connection property will be hidden in the future.

Hence, it's always up to you whether the code is really DB independent or not.

read more comments

Booting Windows from a non-first Disk with GRUB

09.08.2005 at 21:16

As you probably know Windows can only be installed on the first hard disk, but furthermore it can only boot from there. I struggled with this recently while configuring GRUB. I was actually quite confident that my config file was correct (remember grubs naming convention which starts with zero so hd(0,0) refers to the first partition on the first disk) but Windows just didn't boot.

And so I googled for a possible reason and found this FAQ entry. My machine has /dev/hdc reserved for linux while /dev/hdd belongs to a Windows 2003 Server so my entry in /boot/grub/menu.lst now looks like this:

title Windows 2003 Server
   map (hd0)(hd1)
   map (hd1)(hd0)
   chainloader +1

Since grub doesn't count dvd and cdrom drives, in my system hd0 points to /dev/hdc and therefore hd1,0 refers to /dev/hdd1.

Shuting down / rebooting the system with a grub menu entry

I personally find it quite useful to have an entry to shutdown or reboot the PC available in the grub menu, because from time to time it happens that I just want to eject a cdrom without actually starting the operating system so these comes in handy.

title shutdown

title reboot

read more comments

APT Keeps Packages Back

04.08.2005 at 20:05

Ever wondered why apt keeps some packages back when doing an apt-get update && apt-get upgrade?

apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
The following packages have been kept back:
  cpp gcc libcurl3 ssh tasksel x-window-system-core xbase-clients xlibmesa-gl
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.

The message actually means that there is a new package version available but for some reason it can not be installed. Maybe the package has broken or new dependencies. If you want further information about a specific packages this can be done by setting a special options like shown below.

apt-get -s -o Debug::pkgProblemResolver=yes install xutils > /dev/null
Starting 2
Package xutils has broken dep on xbase-clients
  Considering xbase-clients 4 as a solution to xutils 10013
  Added xbase-clients to the remove list
  Fixing xutils via remove of xbase-clients
Package x-window-system-core has broken dep on xbase-clients
  Considering xbase-clients 4 as a solution to x-window-system-core 0
  Re-Instated libglu1-xorg
  Re-Instated libdmx1
  Re-Instated libxkbfile1
  Re-Instated libxkbui1
  Re-Instated libxss1
  Re-Instated libxxf86dga1
  Re-Instated libxxf86misc1
  Re-Instated libxxf86vm1
  Re-Instated xbase-clients
  Re-Instated x-window-system-core
Package xlibmesa-glu has broken dep on libglu1
  Considering libglu1-xorg 0 as a solution to xlibmesa-glu 15
  Added libglu1-xorg to the remove list
  Considering libglu1-mesa 0 as a solution to xlibmesa-glu 15
  Fixing xlibmesa-glu via keep of libglu1-xorg
Package x-window-system-core has broken dep on libglu1-xorg
  Considering libglu1-xorg 0 as a solution to x-window-system-core 0
  Holding Back x-window-system-core rather than change libglu1-xorg

Usually the problem can be resolved by explicitly installing the desired held back packages. For further information check out the APT-Howto.

read more comments

Displaying Recursive Data Structures with Smarty

03.08.2005 at 20:20

For those of you who don't know what smarty is, it is a PHP Templating-Engine whose main idea is to separate program logic from presentation.

A quite common task in web development is to display recursive data structures such as tree menus etc. However, this can be a bit tricky for someone new to smarty. There is currently no built in mechanism for doing so, but with the possibility to include sub files it can be done. Here is how it works.


{include file="menu-recursive.tpl" menu=$menu depth=1}


{foreach name=entry item=entry from=$menu.entries}
    {if $smarty.foreach.entry.first}
        {if $menu.sub}
            {include file="menu-recursive.tpl" menu=$menu.sub depth=$depth+1}
    {if $smarty.foreach.entry.last}
    <p>This category contains currently no entries.</p>

PHP-file with the data structure.

$demo = array(
    'entries' => array('demo 1','demo 2'),
    'sub' => array(
        'entries' => array('demo 1.1','demo 2.1'),
        'sub' => array(
            'entries' => array('demo 1.1.1','demo 2.1.1')


You should get a list looking similar to the one below.

However, whether a designer is able to understand this stuff is a completely different story ...

read more comments

Fluxbox Key Bindings after Switchover to Xorg

02.08.2005 at 21:14

I finally had some time to switch my desktop box over to Xorg. However after the successful upgrade I noticed that my fluxbox key bindings were no longer working. After a while I found out that the Windows, which I am using as a modifier, did no longer work as expected. xmodmap confirmed that:

xmodmap:  up to 2 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x6d)
mod1        Alt_L (0x40)
mod2        Num_Lock (0x4d)
mod3        Mode_switch (0x71)
mod5        Scroll_Lock (0x4e)

So first of all I had to look up the keycode of the windows key. This can be done with xev:

KeyRelease event, serial 25, synthetic NO, window 0x1200001,
    root 0x4b, subw 0x1200002, time 3292297, (45,38), root:(108,116),
    state 0x0, keycode 115 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 bytes:  ""

Now that we know the keycode we can define our modifier:

xmodmap -e 'keycode 115 = Super_L'
xmodmap -e 'add Mod4 = Super_L'

Now xmodmap should print something like this

xmodmap:  up to 2 keys per modifier, (key codes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x6d)
mod1        Alt_L (0x40)
mod2        Num_Lock (0x4d)
mod3        Mode_switch (0x71)
mod4        Super_L (0x73)
mod5        Scroll_Lock (0x4e)

And the modifiers should once again work properly. You can add the two xmodmap commands to your ~/.xsession file, this will adjust the settings on every start of the xserver.

cat >> ~/.xsession << "EOF"
xmodmap -e 'keycode 115 = Super_L'
xmodmap -e 'add Mod4 = Super_L'

read more comments

<< 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 >>