public function updateWhere($table_name, $update_values, $where_with_placeholders, $named_parameters = null) {

            $all_params = empty($named_parameters) ? $update_values : array_merge($update_values, $named_parameters);
            Event::dispatch(EventData::forBefore(Event::BEFORE_UPDATE, $table_name, $all_params, $where_with_placeholders), $update_values);

            $q = $this->config->getSystemIdentifierQuote();
            $sql_query = 'UPDATE ' . $q . $table_name . $q . ' SET ';


            $statement_params = [];
            $null_params = [];

            foreach ($update_values as $field_name => $value) {
                if ($field_name != 'id') {
                    if (strtolower($value) == 'null' || is_null($value)) {
                        $sql_query .= "\n$q" . $field_name . "$q = NULL,";
                        $null_params[ $field_name ] = 'NULL';
                    } else {
                        $sql_query .= "\n$q" . $field_name . "$q = :" . $field_name . ",";
                        $statement_params[ ':' . $field_name ] = $value;
                    }
                }
            }

            $full_param_list = array_merge($null_params, $statement_params);

            // remove trailing comma
            $sql_query = substr($sql_query, 0, -1);

            $sql_query .= ' WHERE ' . $where_with_placeholders;

            // add extra named parameters for where clause
            if ($named_parameters) {
                foreach ($named_parameters as $param => $val) {
                    $statement_params[ $param ] = $val;
                }
            }
            try {
                // prepare the query and bind parameters
                $stmt = $this->db_connection->prepare($sql_query);
                if ($statement_params) {
                    foreach ($statement_params as $k => $v) {
                        $stmt->bindValue($k, $v);
                    }
                }

                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $sql_query, $full_param_list));

                return false;
            }

            $rows_affected = $stmt->rowCount();
            Event::dispatch(EventData::forAfter(Event::AFTER_UPDATE, $table_name, $full_param_list, $sql_query, $rows_affected));

            return $rows_affected;
        }
public function updateWhere($table_name, $update_values, $where_with_placeholders, $named_parameters = null) {

            $all_params = empty($named_parameters) ? $update_values : array_merge($update_values, $named_parameters);
            Event::dispatch(EventData::forBefore(Event::BEFORE_UPDATE, $table_name, $all_params, $where_with_placeholders), $update_values);

            $q = $this->config->getSystemIdentifierQuote();
            $sql_query = 'UPDATE ' . $q . $table_name . $q . ' SET ';


            $statement_params = [];
            $null_params = [];

            foreach ($update_values as $field_name => $value) {
                if ($field_name != 'id') {
                    if (strtolower($value) == 'null' || is_null($value)) {
                        $sql_query .= "\n$q" . $field_name . "$q = NULL,";
                        $null_params[ $field_name ] = 'NULL';
                    } else {
                        $sql_query .= "\n$q" . $field_name . "$q = :" . $field_name . ",";
                        $statement_params[ ':' . $field_name ] = $value;
                    }
                }
            }

            $full_param_list = array_merge($null_params, $statement_params);

            // remove trailing comma
            $sql_query = substr($sql_query, 0, -1);

            $sql_query .= ' WHERE ' . $where_with_placeholders;

            // add extra named parameters for where clause
            if ($named_parameters) {
                foreach ($named_parameters as $param => $val) {
                    $statement_params[ $param ] = $val;
                }
            }
            try {
                // prepare the query and bind parameters
                $stmt = $this->db_connection->prepare($sql_query);
                if ($statement_params) {
                    foreach ($statement_params as $k => $v) {
                        $stmt->bindValue($k, $v);
                    }
                }

                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $sql_query, $full_param_list));

                return false;
            }

            $rows_affected = $stmt->rowCount();
            Event::dispatch(EventData::forAfter(Event::AFTER_UPDATE, $table_name, $full_param_list, $sql_query, $rows_affected));

            return $rows_affected;
        }
public function updateWhere ( $ table_name , $ update_values , $ where_with_placeholders , $ named_parameters = null ) { $ all_params = empty ( $ named_parameters ) ? $ update_values : array_merge ( $ update_values , $ named_parameters ) ; Event :: dispatch ( EventData :: forBefore ( Event :: BEFORE_UPDATE , $ table_name , $ all_params , $ where_with_placeholders ) , $ update_values ) ; $ q = $ this -> config -> getSystemIdentifierQuote ( ) ; $ sql_query = 'UPDATE ' . $ q . $ table_name . $ q . ' SET ' ; $ statement_params = [ ] ; $ null_params = [ ] ; foreach ( $ update_values as $ field_name => $ value ) { if ( $ field_name != 'id' ) { if ( strtolower ( $ value ) == 'null' || is_null ( $ value ) ) { $ sql_query .= "\n$q" . $ field_name . "$q = NULL," ; $ null_params [ $ field_name ] = 'NULL' ; } else { $ sql_query .= "\n$q" . $ field_name . "$q = :" . $ field_name . "," ; $ statement_params [ ':' . $ field_name ] = $ value ; } } } $ full_param_list = array_merge ( $ null_params , $ statement_params ) ; // remove trailing comma $ sql_query = substr ( $ sql_query , 0 , - 1 ) ; $ sql_query .= ' WHERE ' . $ where_with_placeholders ; // add extra named parameters for where clause if ( $ named_parameters ) { foreach ( $ named_parameters as $ param => $ val ) { $ statement_params [ $ param ] = $ val ; } } try { // prepare the query and bind parameters $ stmt = $ this -> db_connection -> prepare ( $ sql_query ) ; if ( $ statement_params ) { foreach ( $ statement_params as $ k => $ v ) { $ stmt -> bindValue ( $ k , $ v ) ; } } $ stmt -> execute ( ) ; } catch ( Exception $ ex ) { Event :: dispatch ( EventData :: forException ( $ ex , $ sql_query , $ full_param_list ) ) ; return false ; } $ rows_affected = $ stmt -> rowCount ( ) ; Event :: dispatch ( EventData :: forAfter ( Event :: AFTER_UPDATE , $ table_name , $ full_param_list , $ sql_query , $ rows_affected ) ) ; return $ rows_affected ; }
Performs an SQL update with a 'WHERE' clause

@param string     $table_name

@param array      $update_values
array( $column_name => $new_value )

@param string     $where_with_placeholders
@param null|array $named_parameters

@return bool|int $rows_affected
Performs an SQL update with a WHERE clause