tags:

views:

181

answers:

2

Hi Guys,

I want to enter some image file that is in ../img/test.jpg into the database

If I do $image = file_get_contents('../img/test.jpg')

And then mysql command "INSERT into table(picture) VALUES ('$image')" it doesn't work.

Any suggestions?

+5  A: 

You need to escape it properly:

mysql_query('INSERT INTO table (picture) VALUES ("'
    . mysql_real_escape_string($image) . '")');
Greg
That did it :) Thx a lot
Mladen
You forgot the quotes.
Gumbo
Oops, fixed. Too used to "?" style
Greg
A: 

Keep the image on the filesystem. You're making MySQL work too hard sending the image through a socket to your PHP script. Then you make Apache work too hard while PHP is blocking waiting for the image data from MySQL.

I don't see a valid reason why you want to save it as a mysql Blob. It gets written to the filesystem anyway by mysql.

Just save the path in MySQL.

bucabay