Question:
how can i insert images in my "MYSQL" database?
ravi L
2009-08-24 12:21:44 UTC
how can i insert images in my "MYSQL" database?
Four answers:
anonymous
2009-08-27 05:22:52 UTC
Images can be inserted in BLOB format





Create a BLOB field.



convert your binary to base64string



Use MySQL's COMPRESS function: INSERT .... VALUES (COMPRESS(string) , ...)



To retreive it: CAST(UNCOMPRESS(string) AS CHAR)



Decode it to display



To display: Imagebox1.Image = Image.FromStream(decoded64String)



This will work definately!
anonymous
2009-08-24 12:31:40 UTC
I believe that there might be a way to do this, but I think you would be MUCH better off just storing the images in a folder and then putting the file-name in the database. Simply have the image uploaded and put into a folder of your choosing, and then store the file-name in your database. Here's a tutorial for the image upload thing:



http://www.tizag.com/phpT/fileupload.php
anonymous
2009-08-25 02:13:37 UTC
(I posted the solution before but for some reason it has not been displayed yet).



The summary of my first post is:



1) Create a BLOB field.

2) convert your binary to base64string using C# (Convert.ToBase64String)

3) Use MySQL's COMPRESS function: INSERT .... VALUES (COMPRESS(string) , ...)

4) To retreive it: CAST(UNCOMPRESS(string) AS CHAR)

5) Decode it using C# (Convert.FromBase64String)

6) To display: Imagebox1.Image = Image.FromStream(decoded64String)



My application is for few users so this works very good for me. (and prevent any byte problem that may exist (according to some ppl) when inserting to the db)
jonatrebol
2009-08-24 15:43:04 UTC
i think it's useless...



in Lua, using wxLua and iup you can store an image as array, and with this you can store in a mysql database, but that's very expensive, i guess.



In case of others languages, just use the binary type.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...