I am developing web application using node.js. I want to store an image into MySQL database.Please give some suggestions.
var Client = require('mysql').Client,
client = new Client();
client.user = DB_USER;
client.password = DB_PASS;
client.host = DB_HOST;
client.connect(function(error, results) {
if(error) {
client.end();
return;
}
client.query('USE ' + DB_SCHEME, function(error, results) {
if(error) {
client.end();
return;
}
var sql = "INSERT INTO b SET `data` = ?";
var values = [buf];
client.query(sql, values,
function(error, results) {
if(error) {
return;
}
return;
}
);
});
});
Here data is blob type.
I really do not understand why do you need to store image into database. Why don't you keep those images in a specific folder and store the image name & path in database and retrieve name & path and use that image when you need?