使用來自Packt的Node Cookbook的mysql模塊和代碼示例。Node.js mySQL模塊錯誤
var mysql = require('mysql');
var client = mysql.createClient({
user: 'root',
password: 'sqlpassword',
//debug: true
});
var ignore = [mysql.ERROR_DB_CREATE_EXISTS,
mysql.ERROR_TABLE_EXISTS_ERROR];
client.on('error', function (err) {
if (ignore.indexOf(err.number) + 1) { return; }
throw err;
});
client.query('CREATE DATABASE quotes');
client.useDatabase('nodb');
client.query('CREATE TABLE quotes.quotes (' +
'id INT NOT NULL AUTO_INCREMENT,' +
'author VARCHAR(128) NOT NULL,' +
'quote TEXT NOT NULL, PRIMARY KEY ( id)' +
')');
client.query('INSERT INTO quotes.quotes (' +
'author, quote) ' +
'VALUES ("Proof by analogy is fraud.", "Bjarne Stroustrup");');
client.end();
和代碼返回我錯誤對象#有沒有方法「useDatabase」
結帳的文檔https://github.com/felixge/node-mysql – zsong 2013-02-17 00:45:22