src/Operations/Update.php
public static function update($id, $keysValues, $table, $idAttribute = 'id', $limit = 1)
    {
        //Work with arrays
        if (is_object($keysValues)) {
            $keysValues = (array)$keysValues;
        }

        $queryKeys = implode('" = ?,"', array_keys($keysValues));
        $queryValues = array_values($keysValues);

        //Push id to the end
        $queryValues[] = $id;

        $tableName = '';

        //Work with array
        if (is_object($table)) {
            $table = (array)$table;
        }

        if (is_array($table)
            && isset($table['schema'])
            && isset($table['table'])
        ) {

            $tableName = sprintf(
                '"%s"."%s"',
                $table['schema'],
                $table['table']
            );
        } else {
            $tableName = sprintf(
                '"%s"',
                $table
            );
        }

        $query = sprintf(
            'UPDATE %s SET "%s" = ?
              WHERE "%s" = ?
              %s',
            $tableName,
            $queryKeys,
            $idAttribute,
            (
                $limit === null
                ? ''
                : '' //'LIMIT ' . $limit
            )
        );

        //Return number of rows affected
        $result = Database::execute($query, $queryValues);

        return $result;
    }
public static function update($id, $keysValues, $table, $idAttribute = 'id', $limit = 1)
    {
        //Work with arrays
        if (is_object($keysValues)) {
            $keysValues = (array)$keysValues;
        }

        $queryKeys = implode('" = ?,"', array_keys($keysValues));
        $queryValues = array_values($keysValues);

        //Push id to the end
        $queryValues[] = $id;

        $tableName = '';

        //Work with array
        if (is_object($table)) {
            $table = (array)$table;
        }

        if (is_array($table)
            && isset($table['schema'])
            && isset($table['table'])
        ) {

            $tableName = sprintf(
                '"%s"."%s"',
                $table['schema'],
                $table['table']
            );
        } else {
            $tableName = sprintf(
                '"%s"',
                $table
            );
        }

        $query = sprintf(
            'UPDATE %s SET "%s" = ?
              WHERE "%s" = ?
              %s',
            $tableName,
            $queryKeys,
            $idAttribute,
            (
                $limit === null
                ? ''
                : '' //'LIMIT ' . $limit
            )
        );

        //Return number of rows affected
        $result = Database::execute($query, $queryValues);

        return $result;
    }
public static function update ( $ id , $ keysValues , $ table , $ idAttribute = 'id' , $ limit = 1 ) { //Work with arrays if ( is_object ( $ keysValues ) ) { $ keysValues = ( array ) $ keysValues ; } $ queryKeys = implode ( '" = ?,"' , array_keys ( $ keysValues ) ) ; $ queryValues = array_values ( $ keysValues ) ; //Push id to the end $ queryValues [ ] = $ id ; $ tableName = '' ; //Work with array if ( is_object ( $ table ) ) { $ table = ( array ) $ table ; } if ( is_array ( $ table ) && isset ( $ table [ 'schema' ] ) && isset ( $ table [ 'table' ] ) ) { $ tableName = sprintf ( '"%s"."%s"' , $ table [ 'schema' ] , $ table [ 'table' ] ) ; } else { $ tableName = sprintf ( '"%s"' , $ table ) ; } $ query = sprintf ( 'UPDATE %s SET "%s" = ?
              WHERE "%s" = ?
              %s' , $ tableName , $ queryKeys , $ idAttribute , ( $ limit === null ? '' : '' //'LIMIT ' . $limit ) ) ; //Return number of rows affected $ result = Database :: execute ( $ query , $ queryValues ) ; return $ result ; }
Update database records
@param  string|integer $id
@param  array|object   $keysValues
@param  string|array   $table                Table's name
@param  string         $idAttribute          **[Optional]** Id attribute
@return integer Return number of affected records
@param  null|integer   $limit                **[Optional]**
Limit clause, when null there is not limit.
@todo Add $additionalAttributes
Update database records