Example #1
0
 public function insert($table, $values)
 {
     $transaction = $this->beginTransaction();
     $id = null;
     try {
         $sql = new \Midori\String("INSERT INTO {$this->quoteIdentifier($table)} ");
         $columns = new Midori_String(" (");
         $fields = new Midori_String(" VALUES (");
         foreach ($values as $column => $field) {
             $columns->append($this->quoteIdentifier($column) . ",");
             $temp = $this->quote($field);
             $fields->append($temp . ",");
         }
         $sql->append($columns->trimEnd(",")->append(")"));
         $sql->append($fields->trimEnd(",")->append(");"));
         $query = $sql->__toString();
         $this->log->sql($query);
         //echo "inserting: $query <br />";
         $stmt = $this->driver->exec($query);
         if ($this->supportsLastId) {
             $id = $this->selectOne($this->getLastInsertId());
         }
         if ($transaction) {
             $this->commit();
         }
     } catch (Exception $ex) {
         //if($transaction)
         //	$this->rollback();
         throw $ex;
     }
     return $id;
 }