I need a way to insert images into a PostgreSQL database without using forms. I have a folder that contains a set of images named say aa.jpg, bb.jpg …. zz.jpg. I also have a table that contains the names aa,bb…zz as individual records.
Now my question is how do I insert these images into the DB without manually using forms. There are loads of Yii tutorials to do the manual insertion, but none explaining how to do it programmatically.
Basically I need a way to use lo_import function in Yii. The thing is, image is a column in the table whose type is OID and my insertion code in Yii is as follows
update('table_name', array(
'image' => "lo_import('$image_path')",
), 'column=:name', array(':name' => $name));
on executing this, it gives me the following error
CDbCommand failed to execute the SQL statement: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type oid:
Solution: Ok, so following @Uday’s answer, I just used the function in Yii to execute sql statements directly.
Yii::app()->db->createCommand($Update_sql_command)->query();
I am all ears if there is a better way to do this.
Thanks!
Do you really need Yii for that? write a function to iterate through all images use
get_file_contents()to get contents and store it to mysql.