PodsData::update PHP Method

update() public method

Update an item, eventually mapping to WPDB::update
Since: 2.0
public update ( string $table, array $data, array $where, array $format = null, array $where_format = null ) : boolean
$table string Table name
$data array Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
$where array A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
$format array (optional) An array of formats to be mapped to each of the values in $data.
$where_format array (optional) An array of formats to be mapped to each of the values in $where.
return boolean
    public function update($table, $data, $where, $format = null, $where_format = null)
    {
        /**
         * @var $wpdb wpdb
         */
        global $wpdb;
        if (strlen($table) < 1 || empty($data) || !is_array($data)) {
            return false;
        }
        if (empty($format)) {
            $format = array();
            foreach ($data as $field) {
                if (isset(self::$field_types[$field])) {
                    $form = self::$field_types[$field];
                } elseif (isset($wpdb->field_types[$field])) {
                    $form = $wpdb->field_types[$field];
                } else {
                    $form = '%s';
                }
                $format[] = $form;
            }
        }
        if (empty($where_format)) {
            $where_format = array();
            foreach ((array) array_keys($where) as $field) {
                if (isset(self::$field_types[$field])) {
                    $form = self::$field_types[$field];
                } elseif (isset($wpdb->field_types[$field])) {
                    $form = $wpdb->field_types[$field];
                } else {
                    $form = '%s';
                }
                $where_format[] = $form;
            }
        }
        list($table, $data, $where, $format, $where_format) = $this->do_hook('update', array($table, $data, $where, $format, $where_format));
        $result = $wpdb->update($table, $data, $where, $format, $where_format);
        if (false !== $result) {
            return true;
        }
        return false;
    }