<?php

class Database {
  private $_dbcnx;
  private $_req = false;

  public function __construct($dbhost, $dbname, $dblogin, $dbpasswd) {
    $this->_dbcnx = new PDO('mysql:host='.$dbhost.';dbname='.$dbname.';charset=utf8', $dblogin, $dbpasswd);

/*
    $this->_dbcnx = false;
    while(!$this->_dbcnx) {
      $this->_dbcnx = new SQLite3($this->_dbfile);
      $this->_dbcnx->busyTimeout(5000);
    }
*/
  }

  public function req($req) {
    if($this->_req) $this->_req->closeCursor();
    $this->_req = $this->_dbcnx->query($req);
    return $this->_req;
  }

  public function next($dbreq) {
    return $dbreq->fetch();
  }

  public function reqFirst($req) {
    $dbreq = $this->req($req);
    if($dbreq)
      return $this->next( $dbreq );
    return false;
  }
}

$db = new Database($__CONF['dbhost'], $__CONF['dbname'], $__CONF['dblogin'], $__CONF['dbpasswd']);

?>