best form of backup

Apparently best form of backup is entirely unconfigured slaves (especially distribution packages). After some destructive cron job kicked in, and executed large large data deletion on master, once slave started executing it, ran out of buffer pool for locks and such, and started crashing. Result: it had all data just up to the destructive action.

Fire it up with –skip-slave-start, crash recovery on default transaction logs is immediate, all data is there – what better backup would one expect?*

* proper snapshots with proper logs

My own database abstraction class

Back in 2006 July, I decided that all other database classes are not worth it, and created my own one, incorporating best features from MySQL and PHP world. It resulted in this brilliant code, which I showed to few colleagues, and got such quote:

i like your nonframework. it gives a fuzzy feeling to the poor souls that think they need an abstraction layer. — Kristian Köhntopp

This was written using TIC pattern and can be used in variety of applications:

class MyDB {
  var $conn = null;

  function MyDB($database=null,$user='root',
                $password='',$host='localhost') {
    $this->conn=mysql_connect($host,$user,$password) and
    $database?mysql_select_db($database, $this->conn):null;

  function _escape($s) {
    return mysql_real_escape_string($s,$this->conn);

  function _quote($s) {
    return "'" . $this->_escape($s) . "'";

  function __call($method,$arguments) {
         'return " ".strtolower($s[0]);'),
    $query=str_replace(' everything ',' * ',$query);
    if ($first) {
      if (is_array($first)) {
        $query .= ' (' . implode(',',
                            $first)) . ') ';
      } else {
        while($argument = array_shift($arguments)) {
          $first = preg_replace('/\?/',
        $query .= $first;
    if (!$res) { print mysql_error(); exit(); }
    while($row=mysql_fetch_assoc($res)) {
    return $ret;


$x = new MyDB('test');
$x->selectEverythingFromMytableWhereIdIn(" (?,?,?) ","a'b",2,3);

Now I wonder where I should build community for this, Google Code or Sourceforge? Or should that be the darling MySQL Forge.

As I started digging my stuff from history, I also managed to upload my past six month pictures to flickr too – including Vienna, Taipei and few other trips.