This article explains uploading image files into a MysQL database using the MySQL C/C++ libraries or MySQL ODBC drivers. When I try to upload image files into MySQL, I was able to read it as bytes or characters but I couldn't insert an image into a MySQL BLOB field using the
ExecuteSQL function in the
Image files contain special characters especially escape sequences. If we want to upload an image file, read it as a string or character constants, and replace all (\) with (\\). My library does this as well. My library function converts unformatted data into formatted data. We can then easily upload it to a MySQL database.
Using the code
The downloadable zip file contains...
The following code snippet describes how to use mysqlfileimportexport.dll.
- Step 1: Include this header file and library file into your code.
Step 2: Write the code for your database connection.
Step 3: Include these lines into your code:
LPSTR Buffer = NULL;
int iReturnValue = lib_Obj.blob_Import("c:\\xx\\yyy.abc",&Buffer);
sQuery.Format("INSERT INTO tablename fieldname(LONGBLOB) VALUES('%s')", Buffer);
Step 4: Execute the query using the database connection variable.
Don't forget to add mysqlfileimportexport.dll in your project directory.