This is my simple statement:
var mysql = require("mysql");
var CONCDB = mysql.createConnection({
host: "localhost",
user: "root",
password: "1234",
database: "pwc"
})
CONCDB.connect();
CONCDB.query("SELECT first_name FROM users LIMIT 1", function(err, rows, fields) {
if (err) throw err;
console.log("The solution is: ", rows);
});
Why I get as result:
[ RowDataPacket { first_name: <Buffer 47 61 62 72 69 65 6c> } ]
If I use
... function(err, results) {
...
console.log("The solution is: ", results)
I get the same as using rows.
Using function(err, rows, fields) and returning fields I get the following:
[ FieldPacket {
catalog: 'def',
db: 'pwc',
table: 'users',
orgTable: 'users',
name: 'first_name',
orgName: 'first_name',
charsetNr: 63,
length: 30,
type: 253,
flags: 4225,
decimals: 0,
default: undefined,
zeroFill: false,
protocol41: true } ]
Sometimes this statement throw:
[Object object]
What am I doing wrong? I cant get the right result. Someone can help me, I am following the same code as others but why this throw me an error?
For example, trying with this: (I saw this in a website)
CONCDB.query('SELECT * from users', function(err, rows, fields) {
if (!err)
console.log('The solution is: ', rows);
else
console.log('Error while performing Query.');
});
The result is:
The solution is: [ RowDataPacket {
id: 1,
first_name: <Buffer 47 61 62 72 69 65 6c>,
last_name: <Buffer 50 65 72 65 69 72 61> } ]