So, if the array length equals 4, then the size of blob data in mysql DB must be 4 bytes. And it works fine with numbers less than 128.node
var res = ""; for(var i = 0; i < arr.length; i++) { res += String.fromCharCode(arr[i]); }
But numbers from 128 to 256 takes 2 bytes.mysql
I tried to use nodejs buffersql
var Buffer = require('buffer').Buffer, buf = new Buffer(arr.length); for(var i = 0; i < arr.length; i++) { buf[i] = arr[i]; } buf.toString('binary');
but the same result. I have no idea how to make it work.less
to store data in mysql database I use node-mysqlide
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; } ); }); });