6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.js + mysql

Posted at

メモ

基本的なメモ。

モジュールのインストール

sudo npm install -g mysql

別に-gはあってもなくても。

簡単なサンプル

db.js
var mysql = require("/usr/local/lib/node_modules/mysql");
var connection = mysql.createConnection({
	host:"localhost",
	database:"testdb",
	user:"dbuser",
	password:"dbpassword"
});

//select
var query = connection.query("select * from members",function(err,results){

	//display error
	if(err){
		console.log(err);
		return;
	}

	//get rows
	for(var i in results){
		console.log(results[i].name + " " + results[i].email);
	}
});

//insert
var query2 = connection.query("insert into members(name,email) values('test','test@test.com')");

connection.end();
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?