/** * Creates and executes an UPDATE SQL statement. * * @param string $table table * @param array $columns array of 'column'=>'value' entries * @param mixed $criteria string where clause or object criteria * * @return boolean|null true if no errors, false if errors encountered */ public function update($table, $columns, $criteria) { if (isset($this->tables[$table])) { $tableDef =& $this->tables[$table]; $where = ''; if (is_scalar($criteria)) { $where = 'WHERE ' . $criteria; } elseif (is_object($criteria)) { $where = $criteria->renderWhere(); } $colSql = ''; foreach ($tableDef['columns'] as $col) { $comma = empty($colSql) ? '' : ', '; if (isset($columns[$col['name']])) { $colSql .= $comma . $col['name'] . ' = ' . $this->db->quote($columns[$col['name']]); } } $sql = "UPDATE `{$tableDef['name']}` SET {$colSql} {$where}"; $this->queue[] = $sql; return true; } else { // no table established $this->lastError = _DB_XMF_TABLE_IS_NOT_DEFINED; $this->lastErrNo = -1; return null; } }