{"id":449,"date":"2017-02-19T13:12:00","date_gmt":"2017-02-19T05:12:00","guid":{"rendered":"http:\/\/www.qdabc.cn\/?p=449"},"modified":"2017-02-19T13:15:24","modified_gmt":"2017-02-19T05:15:24","slug":"node%e4%b9%8bsql%e6%9f%a5%e8%af%a2%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/www.qdabc.cn\/?p=449","title":{"rendered":"node\u4e4bsql\u67e5\u8be2\u9047\u5230\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u5b66\u4e60node\u7684\u7ae5\u978b\u4eec\uff0c\u4e0d\u77e5\u9053\u4f60\u4eec\u6709\u6ca1\u6709\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5c31\u662f\u5728sql\u7684\u65f6\u5019\uff0c\u5b89\u88c5\u597dMySQL\u5305\u4e4b\u540e\u67e5\u8be2\u4e0d\u80fd\u6b63\u786e\u7684\u52a0\u8f7dMySQL\u5305\u3002\u4ee5\u5168\u5c40\u7684\u65b9\u5f0f\u5b89\u88c5MySQL\uff0c\u8fd8\u662f\u4e0d\u80fd\u6b63\u5e38\u8fd0\u884c\uff0c\u90a3\u600e\u4e48\u89e3\u51b3\u5462\uff1f\u51fa\u73b0\u8fd9\u6837\u7684\u95ee\u9898\u662f\u56e0\u4e3aMySQL\u5305\u7684\u4f4d\u7f6e\u548cjs\u6587\u4ef6\u4e0d\u5728\u4e00\u4e2a\u76ee\u5f55\u4e0b\uff0c\u67e5\u770b\u4e0b\u91cd\u65b0\u5b89\u88c5\u4e00\u4e0b\u5427\uff0c\u8981\u786e\u5b9ajs\u6587\u4ef6\u8981\u4e0e\u5305\u653e\u7f6e\u5230\u540c\u4e00\u76ee\u5f55\u4e0b\u624d\u884c\u3002\u4e0b\u9762\u9644\u4e0a\u6e90\u4ee3\u7801\u4f9b\u5927\u5bb6\u5b66\u4e60<\/p>\n<h3>sql\u67e5\u8be2<\/h3>\n<pre class=\"brush:js;toolbar:false\">var mysql   = require('mysql');\r\nvar connection = mysql.createConnection({\r\n    host   : '127.1.0.1',\r\n    user   : 'root',\r\n    password : 'root',\r\n    database : 'test'\r\n});\r\nconnection.connect();\r\nconnection.query(\"SELECT * from testName WHERE `name`='misaka'\", function(err, rows, fields) {\r\n    if (err) {\r\n    throw err;\r\n    }\r\n    var soul=new String();\r\n    for(i in rows[0]){\/\/\u56e0\u4e3a\u6211\u77e5\u9053\u53ea\u6709\u4e00\u884c\u6570\u636e\r\n        soul+=rows[0][i]+\" \";\r\n    }\r\n    console.log('The solution is: ', soul);\r\n});\r\nconnection.end();<\/pre>\n<h3>mssql<\/h3>\n<pre class=\"brush:js;toolbar:false\">var sql = require('mssql');\r\nvar config = {\r\n    user: 'root',\r\n    password: 'root',\r\n    server: '127.1.0.1', \/\/ You can use 'localhost\\\\instance' to connect to named instance\r\n    database: 'test',\r\n    options: {\r\n        encrypt: true \/\/ Use this if you're on Windows Azure\r\n    }\r\n}\r\n\r\nsql.connect(config).then(function() {\r\n    \/\/ Query\r\n    console.log(\"enter\");\r\n    input_parameter='fred';\r\n    new sql.Request()\r\n    .input('input_parameter', sql.Int, value)\r\n    .query('select * from test where name = @input_parameter').then(function(recordset) {\r\n        console.dir(recordset);\r\n    }).catch(function(err) {\r\n        \/\/ ... error checks\r\n    });\r\n    \/\/ Stored Procedure\r\n    \/*new sql.Request();\r\n    .input('input_parameter', sql.Int, value);\r\n    .output('output_parameter', sql.VarChar(50));\r\n    .execute('procedure_name').then(function(recordsets) {\r\n        console.dir(recordsets);\r\n    }).catch(function(err) {\r\n        \/\/ ... error checks\r\n    });*\/\r\n}).catch(function(err) {\r\n    \/\/ ... error checks\r\n});<\/pre>\n<p class=\"post-copyright\">\u6b22\u8fce\u5206\u4eab\u672c\u6587\uff0c\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u51fa\u5904\uff1a<a href=\"http:\/\/www.qdabc.cn\">\u524d\u7aefABC<\/a> &raquo; <a href=\"http:\/\/www.qdabc.cn\/?p=449\">node\u4e4bsql\u67e5\u8be2\u9047\u5230\u7684\u95ee\u9898<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u5b66\u4e60node\u7684\u7ae5\u978b\u4eec\uff0c\u4e0d\u77e5\u9053\u4f60\u4eec\u6709\u6ca1\u6709\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5c31\u662f\u5728sql\u7684\u65f6\u5019\uff0c\u5b89\u88c5\u597dMySQL\u5305\u4e4b\u540e\u67e5\u8be2\u4e0d\u80fd\u6b63\u786e\u7684\u52a0\u8f7dMySQL\u5305\u3002\u4ee5\u5168\u5c40\u7684\u65b9\u5f0f\u5b89\u88c5MySQL\uff0c\u8fd8\u662f\u4e0d\u80fd\u6b63\u5e38\u8fd0\u884c\uff0c\u90a3\u600e\u4e48\u89e3\u51b3\u5462\uff1f\u51fa\u73b0\u8fd9\u6837\u7684\u95ee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":99,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[9,33,107],"_links":{"self":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/449"}],"collection":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=449"}],"version-history":[{"count":3,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":452,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions\/452"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/media\/99"}],"wp:attachment":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}