zoukankan      html  css  js  c++  java
  • LUA利用第三方API访问数据库

    ===========数据库访问--第三方

    http {
    upstream backend {
    drizzle_server 192.168.4.119:3306 protocol=mysql
    dbname=igirl user=root password=123456;
    drizzle_keepalive max=10 overflow=ignore mode=single;
    }
    server {
    listen 8080;
    location /lua_content {
    # MIME type determined by default_type:
    default_type 'text/plain';
    content_by_lua_block {
    ngx.say('Hello,world!')
    }
    }
    location /mysql {
    drizzle_query $echo_request_body;
    drizzle_pass backend;
    }
    location /api {
    content_by_lua '
    local sql = "select * from p_user"
    local resp = ngx.location.capture("/mysql", {
    method = ngx.HTTP_POST, body = sql
    })
    if resp.status ~= ngx.HTTP_OK or not resp.body then
    error("failed to query mysql")
    end
    local parser = require "rds.parser"
    local res, err = parser.parse(resp.body)
    if res == nil then
    error("failed to parse RDS: " .. err)
    end
    local rows = res.resultset
    if not rows or #rows == 0 then
    ngx.say("empty resultset")
    ngx.exit(0)
    end
    for i, row in ipairs(rows) do
    ngx.print("row ", i, ": ")
    for col, val in pairs(row) do
    if val ~= parser.null then
    ngx.print(col, "=", val, " ")
    else
    ngx.print(col, "=null ")
    end
    end
    ngx.say()
    end
    ';
    }
    }

    }

  • 相关阅读:
    多态中的虚析构函数
    mysql-2-where
    mysql-1-select
    高维稀疏数据的异常检测
    隐马尔可夫模型 Hidden Markov Model
    协同过滤 Collaborative Filtering
    内容推荐
    推荐系统中的基本问题
    HDR视频生态圈追踪
    从强提醒说起——社交场景下的万有“隐力”
  • 原文地址:https://www.cnblogs.com/justart/p/12374685.html
Copyright © 2011-2022 走看看