conn = $conn; } function getType() { return $this->conn->getType(); } function select($table, $criteria = null, $order = '') { $query = $this->getSelectQuery($table); if($criteria) $query->addCriteria(lmbSQLCriteria :: objectify($criteria)); if($order) $query->addOrder($order); return $query->getRecordSet($this->conn); } function selectAsArray($table, $criteria = null, $order = '', $key_field = '') { $rs = $this->select($table, $criteria, $order); return $rs->getArray($key_field); } function getFirstRecordFrom($table_name, $criteria = null, $order = '') { $rs = $this->select($table_name, $criteria, $order); $rs->rewind(); if($rs->valid()) return $rs->current(); else return new lmbSet(); } function count($table_name, $criteria = null) { $rs = $this->select($table_name, $criteria); return $rs->count(); } function getSelectQuery($table) { $query = new lmbSelectQuery(null, $this->conn); $query->addTable($table); return $query; } function insert($table, $values, $primary_key = 'id') { $query = new lmbInsertQuery($table, $this->conn); foreach($values as $key => $value) $query->addField($key , $value); $stmt = $query->getStatement($this->conn); if($primary_key) { if(isset($values[$primary_key])) { $stmt->execute(); return $values[$primary_key]; } else return $stmt->insertId($primary_key); } else $stmt->execute(); } function update($table, $values, $criteria = null) { $query = new lmbUpdateQuery($table, $this->conn); if($criteria) $query->addCriteria(lmbSQLCriteria :: objectify($criteria)); foreach($values as $key => $value) $query->addField($key, $value); $stmt = $query->getStatement($this->conn); $stmt->execute(); return $stmt->getAffectedRowCount(); } function delete($table, $criteria = null) { $query = new lmbDeleteQuery($table, $this->conn); if($criteria) $query->addCriteria(lmbSQLCriteria :: objectify($criteria)); $stmt = $query->getStatement($this->conn); $stmt->execute(); return $stmt->getAffectedRowCount(); } function truncateDb() { $info = $this->conn->getDatabaseInfo(); foreach($info->getTableList() as $table) $this->conn->newStatement("DELETE FROM $table")->execute(); } function disconnect() { $this->conn->disconnect(); } function begin() { $this->conn->beginTransaction(); } function commit() { $this->conn->commitTransaction(); } function rollback() { $this->conn->rollbackTransaction(); } } ?>