拉取後台資料

來源:互聯網
上載者:User

標籤:style   http   os   io   檔案   資料   ar   cti   

----------------------------------------------------------------------------------

/** --

 * Created by Administrator on 14-8-16. --

 *類比Ajax把資料從資料庫中調用出來/後台執行此代碼如下/ --

 */ --

var http = require(‘http‘);/建立伺服器的操作/ --

--

http.createServer(function(request,response){ --

    response.writeHead(200,{‘Content-Type‘:‘text/plain;charset=utf-8‘}); --

    getdb(request,response); --

}).listen(8080); --

--

var db = require(‘./select.js‘);/連結select.js檔案/ --

/下述代碼實現的是連結的伺服器和資料庫的操作/ --

function getdb(request,response){ --

//    類比Ajax強行輸出“請求”為:zzq --

    request = ‘zzq‘; --

    db.a(); --

    db.b(request,response); --

    db.c(); --

} --

--

------------------------------------------------------------ --

/** --

 * Created by Administrator on 14-8-16. --

 */暴露介面/ --

 */ --

var mainline = require(‘./../shuju/mysql‘);/*載入資料庫*/ --

/*連結資料庫並且暴露資料連接埠*/ --

--

var conjs; --

exports.a =function(){ --

     conjs = mainline.createConnection({ --

        host:‘localhost‘, --

        user:‘root‘, --

        password:‘name‘, --

        database:‘test‘ --

    }); --

    return conjs; --

} --

--

exports.b =function(request,response){ --

    var sql ="select*from f08_4 where usen=?"; --

/查詢conjs資料庫中滿足條件的資料/ --

    conjs.query(sql,[‘zzq‘],function(err,re){ --

        if(err){ --

            console.log(err); --

        } --

        else{console.log(re); --

            response.write(""+re); --

/上述代碼錶示響應後返回資料/ --

            response.end(); --

        } --

    }); --

} --

exports.c=function(){ --

    conjs.end(); --

/上述語句執行的是結束資料的查詢/ --

} --

----------------------------------------------------------------------------------


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.