protected static function saveFieldData($entry_id, $field_id, $field)
    {
        // Check that we have a field id
        if (empty($field_id)) {
            return;
        }

        // Ignore parameter when not an array
        if (!is_array($field)) {
            $field = array();
        }

        $did_lock = false;
        $exception = null;
        try {

            // Check if table exists
            $table_name = 'tbl_entries_data_' . General::intval($field_id);
            if (!Symphony::Database()->tableExists($table_name)) {
                return;
            }

            // Lock the table for write
            $did_lock = Symphony::Database()->query("LOCK TABLES `$table_name` WRITE");

            // Delete old data
            Symphony::Database()->delete($table_name, sprintf("
                `entry_id` = %d", $entry_id
            ));

            // Insert new data
            $data = array(
                'entry_id' => $entry_id
            );

            $fields = array();

            foreach ($field as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $ii => $v) {
                        $fields[$ii][$key] = $v;
                    }
                } else {
                    $fields[max(0, count($fields) - 1)][$key] = $value;
                }
            }

            foreach ($fields as $index => $field_data) {
                $fields[$index] = array_merge($data, $field_data);
            }

            // Insert only if we have field data
            if (!empty($fields)) {
                Symphony::Database()->insert($fields, $table_name);
            }
        } catch (Exception $ex) {
            $exception = $ex;
            Symphony::Log()->pushExceptionToLog($ex, true);
        }

        if ($did_lock) {
            Symphony::Database()->query('UNLOCK TABLES');
        }

        if ($exception) {
            throw $exception;
        }
    }
protected static function saveFieldData($entry_id, $field_id, $field)
    {
        // Check that we have a field id
        if (empty($field_id)) {
            return;
        }

        // Ignore parameter when not an array
        if (!is_array($field)) {
            $field = array();
        }

        $did_lock = false;
        $exception = null;
        try {

            // Check if table exists
            $table_name = 'tbl_entries_data_' . General::intval($field_id);
            if (!Symphony::Database()->tableExists($table_name)) {
                return;
            }

            // Lock the table for write
            $did_lock = Symphony::Database()->query("LOCK TABLES `$table_name` WRITE");

            // Delete old data
            Symphony::Database()->delete($table_name, sprintf("
                `entry_id` = %d", $entry_id
            ));

            // Insert new data
            $data = array(
                'entry_id' => $entry_id
            );

            $fields = array();

            foreach ($field as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $ii => $v) {
                        $fields[$ii][$key] = $v;
                    }
                } else {
                    $fields[max(0, count($fields) - 1)][$key] = $value;
                }
            }

            foreach ($fields as $index => $field_data) {
                $fields[$index] = array_merge($data, $field_data);
            }

            // Insert only if we have field data
            if (!empty($fields)) {
                Symphony::Database()->insert($fields, $table_name);
            }
        } catch (Exception $ex) {
            $exception = $ex;
            Symphony::Log()->pushExceptionToLog($ex, true);
        }

        if ($did_lock) {
            Symphony::Database()->query('UNLOCK TABLES');
        }

        if ($exception) {
            throw $exception;
        }
    }
protected static function saveFieldData ( $ entry_id , $ field_id , $ field ) { // Check that we have a field id if ( empty ( $ field_id ) ) { return ; } // Ignore parameter when not an array if ( ! is_array ( $ field ) ) { $ field = array ( ) ; } $ did_lock = false ; $ exception = null ; try { // Check if table exists $ table_name = 'tbl_entries_data_' . General :: intval ( $ field_id ) ; if ( ! Symphony :: Database ( ) -> tableExists ( $ table_name ) ) { return ; } // Lock the table for write $ did_lock = Symphony :: Database ( ) -> query ( "LOCK TABLES `$table_name` WRITE" ) ; // Delete old data Symphony :: Database ( ) -> delete ( $ table_name , sprintf ( "
                `entry_id` = %d" , $ entry_id ) ) ; // Insert new data $ data = array ( 'entry_id' => $ entry_id ) ; $ fields = array ( ) ; foreach ( $ field as $ key => $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ ii => $ v ) { $ fields [ $ ii ] [ $ key ] = $ v ; } } else { $ fields [ max ( 0 , count ( $ fields ) - 1 ) ] [ $ key ] = $ value ; } } foreach ( $ fields as $ index => $ field_data ) { $ fields [ $ index ] = array_merge ( $ data , $ field_data ) ; } // Insert only if we have field data if ( ! empty ( $ fields ) ) { Symphony :: Database ( ) -> insert ( $ fields , $ table_name ) ; } } catch ( Exception $ ex ) { $ exception = $ ex ; Symphony :: Log ( ) -> pushExceptionToLog ( $ ex , true ) ; } if ( $ did_lock ) { Symphony :: Database ( ) -> query ( 'UNLOCK TABLES' ) ; } if ( $ exception ) { throw $ exception ; } }
Executes the SQL queries need to save a field's data for the specified
entry id.

It first locks the table for writes, it then deletes existing data and then
it inserts a new row for the data. Errors are discarded and the lock is
released, if it was acquired.

@param int $entry_id
The entry id to save the data for
@param int $field_id
The field id to save the data for
@param array $field
The field data to save
Executes the SQL queries need to save a field s data for the specified entry id .