Node.js returning result from MySQL query

You have to do the processing on the results from the db query on a callback only. Just like. function getColour(username, roomCount, callback) { connection.query(‘SELECT hexcode FROM colours WHERE precedence = ?’, [roomCount], function(err, result) { if (err) callback(err,null); else callback(null,result[0].hexcode); }); } //call Fn for db query with callback getColour(“yourname”,4, function(err,data){ if (err) { … Read more

MySQL Query to calculate the Previous Month

Here you go, use this to get the date between the 1st of last month and the last of last month in MySQL: … order_placed_date BETWEEN DATE_FORMAT(NOW() – INTERVAL 1 MONTH, ‘%Y-%m-01 00:00:00’) AND DATE_FORMAT(LAST_DAY(NOW() – INTERVAL 1 MONTH), ‘%Y-%m-%d 23:59:59’)

Using MySQL triggers to log all table changes to a secondary table

The insert syntax is INSERT INTO table (columns_list) VALUES (values_list) so your insert would look something like this (i’m not a MySQL expert but you can fit the query): INSERT INTO data_tracking (`data_id` , `field` , `old_value` , `new_value` , `modified` ) VALUES (NEW.data_id, ‘field1’, OLD.field, NEW.field, CURRENT_DATETIME()); And repeat it for variation on field2 … Read more

In MySQL SERVER 8.0 the PASSWORD function not working

If you need a replacement hash to match the password() function, use this: SHA1(UNHEX(SHA1())); E.g. mysql> SELECT PASSWORD(‘mypass’); +——————————————-+ | PASSWORD(‘mypass’) | +——————————————-+ | *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4 | +——————————————-+ and replacement that gives the same answer in version 8: mysql> SELECT CONCAT(‘*’, UPPER(SHA1(UNHEX(SHA1(‘mypass’))))); +————————————————-+ | CONCAT(‘*’, UPPER(SHA1(UNHEX(SHA1(‘mypass’))))) | +————————————————-+ | *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4 | +————————————————-+


You can insert/update multiple rows using INSERT … ON DUPLICATE KEY UPDATE. The documentation has the following example: INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b); Or am I misunderstanding your question?