Lunedì 08 Aprile 2019, To upload image in mysql database as a BLOB(Binary Large OBject). You need to follow several steps :
1. Create html(Hypertext Markup Language) form - the form should have a multipart/form-data as the enctype located inside the form tags. Also in the form tags you should include action and method tags. Action specifies where the code form will be processed, You can process it on the same page with the form by leaving its value to blank. Method is either POST or GET.
Any method can be used. Post is used to sent large amount of data and its also secure. Get on the other hand is used to send parameters as a part of the url, hence not secure when sending private data. Make sure input tag where the image is place is of type file. Also set the name. The name will be used to retrieve file value on the server side. You can add another input tag for submit button. The should be pretty all for the form.
2. Connect to database - Connecting to mysql database is the next thing after form creation. To connect to the database you need server name, username, password and database name.
3. Create database and table - Give your database a name if it not created yet, and create it. Then create a table where images will be saved. Image must have one column which is of type BLOB. BLOB means binary large objects. And is the datatype used to store images.
MySQL has four BLOB types:
-TINYBLOB
-BLOB
-MEDIUMBLOB
-LONGBLOB
You can use any of the above datatypes when dealing with images.
4. Upload and display image - To upload image to the database you need sql(Structured Query Language) queries, which will be executed with the help of PHP(Hypertext Preprocessor) language. there should be queries for inserting data in the database and selecting or retrieving data.