var sys = require('sys');

var Client = require('mysql').Client;
var client = new Client(); client.user = 'someuser';
client.password = 'password'; console.log('Connecting to MySQL...'); client.connect(function(error, results) {
if(error) {
console.log('Connection Error: ' + error.message);
return;
}
console.log('Connected to MySQL');
ClientConnectionReady(client);
}); ClientConnectionReady = function(client)
{
client.query('USE NodeSample', function(error, results) {
if(error) {
console.log('ClientConnectionReady Error: ' + error.message);
client.end();
return;
}
ClientReady(client);
});
}; ClientReady = function(client)
{
var values = ['Chad', 'Lung', 'Hello World'];
client.query('INSERT INTO MyTable SET firstname = ?, lastname = ? , message = ?', values,
function(error, results) {
if(error) {
console.log("ClientReady Error: " + error.message);
client.end();
return;
}
console.log('Inserted: ' + results.affectedRows + ' row.');
console.log('Id inserted: ' + results.insertId);
}
);
GetData(client);
} GetData = function(client)
{
client.query(
'SELECT * FROM MyTable',
function selectCb(error, results, fields) {
if (error) {
console.log('GetData Error: ' + error.message);
client.end();
return;
}
// Uncomment these if you want lots of feedback
//console.log('Results:');
//console.log(results);
//console.log('Field metadata:');
//console.log(fields);
//console.log(sys.inspect(results)); if(results.length > 0)
{
var firstResult = results[0];
console.log('First Name: ' + firstResult['firstname']);
console.log('Last Name: ' + firstResult['lastname']);
console.log('Message: ' + firstResult['message']);
}
}); client.end();
console.log('Connection closed');
};

最新文章

  1. linux下给网卡加VLAN标签和私网地址
  2. 使用 Linq 对多个对象进行join操作 C#
  3. ios coredata 无任何错误提示crash
  4. 第一次div1做出3道题
  5. Fragstats景观分析研究
  6. cglib源码分析(四):cglib 动态代理原理分析
  7. ASP.NET跨页面传值技巧
  8. linux下实现ls()函数遍历目录
  9. HDU 3488Tour(流的最小费用网络流)
  10. Android-采用Matrix对Bitmap加工
  11. vue学习记录②(hello world!)
  12. getQueryStringByName url参数/
  13. C++的成员初始化列表和构造函数体(以前未知)
  14. 一、I/O操作(中文问题)
  15. leaflet入门(一)示例
  16. apache不能启动LoadModule php5_module modules/ph
  17. Python --标准库 存储对象 (pickle包,cPickle包)
  18. python爬虫入门(2)re模块-正则表达式
  19. jvm 哪些是不会被gc回收的
  20. js中的typeof name

热门文章

  1. DOM 事件与事件委托
  2. vue大型电商项目尚品汇(前台篇)day01
  3. ElasticSearch基础学习(SpringBoot集成ES)
  4. 用了Scrum越来越累?这三点帮你走出困境
  5. JavaSE_多线程入门 线程安全 死锁 状态 通讯 线程池
  6. [python][flask] Flask 图片上传与下载例子(支持漂亮的拖拽上传)
  7. Koa系框架(egg/cabloy)如何获取微信支付回调请求中的xml参数
  8. python生产exe文件yi以及解释器配置等
  9. JavaScript之parseInt()方法
  10. 用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性