/** * Create a full fieldname OR create a full tablename * * @param string $group Table name / DB name * @param string $name Field name / Table name * @param string $alias * @return boolean */ public function makeIdentifier($group, $name, $alias = null) { return $this->sqlSplitter->makeIdentifier($group, $name, $alias); }
/** * Create query to update rows of a table. * * @param string $table * @param array $columns Assasioted array as (column=>value, ...) * @param string|array $criteria WHERE expression or array(column=>value, ...) * @param int $flags Options as bitset * @return string */ public static function buildUpdateStatement($table = null, $columns = null, $criteria = null, $flags = 0) { $sql_set = array(); foreach ($columns as $column => &$value) { $sql_set[] = self::quoteIdentifier($column) . '=' . self::quote($value); } if (!is_scalar($criteria)) { array_walk($criteria, function (&$value, $key) use($table) { $value = DB_MySQL_SQLSplitter::buildWhere(DB_MySQL_SQLSplitter::makeIdentifier($table, $key, null, $flags), $value); }); $criteria = join($flags & DB::GLUE_OR ? ' OR ' : ' AND ', $criteria); } return "UPDATE" . (isset($table) ? ' ' . self::quoteIdentifier($table, $flags) : null) . (!empty($sql_set) ? " SET " . join(', ', $sql_set) : null) . (isset($criteria) ? " WHERE {$criteria}" : null); }