Purely record the most basic writing, almost no logic to write, the wording is not very perfect (because I have just groped to write this can ... = =!) Hope Master advice also want to be able to help than I also new novice ....
1.insert operation
Let Insertsql = ' insert INTO User ' (username,password,name,gender,age) VALUES (?,?,?,?,?) '; Let Insertparams = [username, password, name, gender, Age];mysqlconnection.query (insertsql, insertparams, function ( Error, results, fields) {if (error) throw error; return results;});//2.select operation (I found in my own test, string type of column, to add extra quotes to the parameter, otherwise it will be treated as a numeric type or column name)Let Selectsql = ' Select id from User where username = \ '. Concat (username, ' \ ' and password = \ ', password, ' \ '); Mysqlco Nnection.query (Selectsql, function (Error, results, fields) {if (error) throw error; return results;});//3.delete OperationLet Deletesql = ' Delete from user where id = \ '. Concat (ID, ' \ '); Mysqlconnection.query (Deletesql, function (Error, result s, fields) {if (error) throw error; return results;});//4.update OperationLet Updatesql = ' update User set ' age = ' WHERE id = ' '. Concat (ID, ' \ '); Mysqlconnection.query (Updatesql, function (Error , results, fields) {if (error) throw error; return results;});
Nodejs MySQL in the additions and deletions to change the operation