Nodejs MySQL in the additions and deletions to change the operation

Source: Internet
Author: User
Tags mysql in

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.