CodeIgniter Forums

Full Version: Decryption of data before creating CSV file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a database table that I need to convert into a CSV file using the DB Utility library's csv_from_result() function
however I need to run encryption->decrypt() on a few of the columns before I build the CSV. I can't create a new array of unencrypted data because csv_from_result() requires a valid db result object, not an array. Is there a way to do this?
Place these into one of your helper files.

PHP Code:
// -----------------------------------------------------------------------

if ( ! function_exists('objectToArray'))
{
    /**
     * objectToArray ()
     * -------------------------------------------------------------------
     *
     * @param  $data
     * @return array
     */
    function objectToArray(object $data) : array
    {
        if (is_object($data))
        {
            /**
             * Gets the properties of the given object
             * with get_object_vars function
             */
            $data get_object_vars($data);
        }

        /**
         * Return array converted to object Using __FUNCTION__ (Magic constant)
         * for recursive call
         */
        return (is_array($data)) ? array_map(__FUNCTION__$data) : $data;
    }
}

// -----------------------------------------------------------------------

if ( ! function_exists('arrayToObject'))
{
    /**
     * arrayToObject ()
     * -------------------------------------------------------------------
     *
     * @param  $data
     * @return object
     */
    function arrayToObject(array $data) : object
    
{
        /**
         * Return array converted to object Using __FUNCTION__ (Magic constant)
         * for recursive call
         */
        return (is_array($data)) ? (object) array_map(__FUNCTION__$data) : $data;
    }


Method objectToArray converts an object to an array
Method arrayToObject converts an array to an object