/** * Returns an update query object. * * @param string $table_name Name of the main table you're updating (= first table in the update clause). * @param GlueDB_Fragment_Aliased_Table $alias Table alias object you may use to refer to the table columns. * * @return GlueDB_Fragment_Query_Update */ public static function update($table_name, &$alias = null) { $query = new GlueDB_Fragment_Query_Update(); $query->from($table_name, $alias); return $query->from(); }
/** * Compiles GlueDB_Fragment_Query_Update fragments into an SQL string. * * @param GlueDB_Fragment_Query_Update $fragment * * @return string */ public function compile_query_update(GlueDB_Fragment_Query_Update $fragment) { // Get data from fragment : $setlistsql = $fragment->set()->sql($this); $fromsql = $fragment->from()->sql($this); $wheresql = $fragment->where()->sql($this); $orderbysql = $fragment->orderby()->sql($this); // Mandatory : $sql = 'UPDATE ' . $fromsql . ' SET ' . $setlistsql; // Optional : if (!empty($wheresql)) { $sql .= ' WHERE ' . $wheresql; } if (!empty($orderbysql)) { $sql .= ' ORDER BY ' . $orderbysql; } return $sql; }