Welcome Guest, Not a member yet? Register   Sign In
Decryption of data before creating CSV file
#1

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?
Reply
#2

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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB