Skip to content

Instantly share code, notes, and snippets.

@ryanbekabe
Created October 30, 2020 07:00
Show Gist options
  • Save ryanbekabe/6c9bd7c0218ac3930fd07bff073c3ed5 to your computer and use it in GitHub Desktop.
Save ryanbekabe/6c9bd7c0218ac3930fd07bff073c3ed5 to your computer and use it in GitHub Desktop.
/*CREATE TABLE IF NOT EXISTS `product` (
`product_id` int(11) NOT NULL AUTO_INCREMENT,
`product_name` varchar(200) DEFAULT NULL,
`product_price` int(11) DEFAULT NULL,
PRIMARY KEY (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
*/
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "toor",
database: "sampledb"
});
con.connect(function(err){
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO product (product_id, product_name, product_price) VALUES ('1', 'Server HanyaJasa.Com', '100000')";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Completed!");
});
con.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment