/** * Inserts a table row with specified data. * * @param EhrlichAndreas_AbstractCms_Abstract_Adapter_Abstract|EhrlichAndreas_Db_Adapter_Abstract|Zend_Db_Adapter_Abstract $adapter * @param string $table * @param array $param * Column-value pairs. * @param string $returnAsString * Return the computed query as string. * @return int number of affected rows. * @throws Exception */ public function insert($adapter, $table, $params = array(), $returnAsString = false) { $db = EhrlichAndreas_AbstractCms_Abstract_Model::getConnection($adapter); if (is_string($params)) { $query = $params; } elseif (!EhrlichAndreas_Util_Object::isInstanceOf($params, 'EhrlichAndreas_Db_Insert')) { $query = new EhrlichAndreas_Db_Insert($db); foreach ($params as $key => $value) { $escape = true; if (is_array($value)) { if (array_key_exists('escape', $value) && !is_null($value['escape'])) { $escape = $value['escape']; } elseif (count($value) == 2 && array_key_exists(0, $value) && array_key_exists(1, $value) && !is_null($value[1]) && is_bool($value[1])) { $escape = $value[1]; } if (isset($value['value'])) { $value = $value['value']; } elseif (array_key_exists(0, $value)) { $value = $value[0]; } else { $value = array_shift($value); } } elseif (is_object($value) && method_exists($value, '__toString')) { $value = $value->__toString(); $escape = false; } $escape = (bool) intval($escape); if (!$escape) { $value = new EhrlichAndreas_Db_Expr($value); } $query->insert($key, $value); } } else { $query = $params; } if (!is_string($query)) { $query->into($table); $query = $query->assemble(); } if ($returnAsString) { return $query; } $stmt = $db->query($query); $return = $db->lastInsertId($table); $stmt->closeCursor(); return $return; }
/** * * @param Zend_Db_Adapter_Abstract $dbAdapter * @param string $tableVersion * @param string $version * @return type */ protected function _setVersion($dbAdapter, $tableVersion, $version = 0) { $query = new EhrlichAndreas_Db_Insert($dbAdapter); $query->into($tableVersion); $query->insert('num', $version); $sql = $query->assemble(); try { $stmt = $dbAdapter->query($sql); $result = $stmt->rowCount(); } catch (Exception $e) { $result = false; } if ($result) { $this->version = $version; } return $result; }