<?php
abstract class Dao {
  private $conn = NULL;
  public function __construct() {
    //if (!$this->conn = @mysql_connect('mysql442.db.sakura.ne.jp', 'tns-g', 'tns-goss')) {
    if (!$this->conn = @mysql_connect('localhost', 'root', '')) {
      exit('500 Internal Server Error');
    }
    @mysql_query("SET NAMES utf8", $this->conn);
    if (!@mysql_select_db('tns-g_qjin', $this->conn)) {
      exit('500 Internal Server Error');
    }
  }
  protected function execute($sql, $params = '', $escape = TRUE) {
    if (!empty($params)) {
      $params = is_array($params) ? $params : array($params);
      if ($escape) {
        foreach ($params as $key => $val) {
          $params[$key] = mysql_real_escape_string($val, $this->conn);
        }
      }
      $sql = vsprintf($sql, $params);
    }
    return @mysql_query($sql, $this->conn);
  }
  public abstract function getAll();
  public abstract function getByPk($pk);
}
// EOF.
