国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

Lua 數(shù)據(jù)庫(kù)訪(fǎng)問(wèn)

2022-01-29 10:35 更新

本文主要為大家介紹 Lua 數(shù)據(jù)庫(kù)的操作庫(kù):LuaSQL。他是開(kāi)源的,支持的數(shù)據(jù)庫(kù)有:ODBC, ADO, Oracle, MySQL, SQLite 和 PostgreSQL。

本文為大家介紹MySQL的數(shù)據(jù)庫(kù)連接。

LuaSQL 可以使用 LuaRocks 來(lái)安裝可以根據(jù)需要安裝你需要的數(shù)據(jù)庫(kù)驅(qū)動(dòng)。

LuaRocks 安裝方法:

$ wget http://luarocks.org/releases/luarocks-2.2.1.tar.gz
$ tar zxpf luarocks-2.2.1.tar.gz
$ cd luarocks-2.2.1
$ ./configure; sudo make bootstrap
$ sudo luarocks install luasocket
$ lua
Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> require "socket"

Window 下安裝 LuaRocks:https://github.com/keplerproject/luarocks/wiki/Installation-instructions-for-Windows

安裝不同數(shù)據(jù)庫(kù)驅(qū)動(dòng):

luarocks install luasql-sqlite3
luarocks install luasql-postgres
luarocks install luasql-mysql
luarocks install luasql-sqlite
luarocks install luasql-odbc

你也可以使用源碼安裝方式,Lua Github 源碼地址:https://github.com/keplerproject/luasql

Lua 連接MySql 數(shù)據(jù)庫(kù):

require "luasql.mysql"

--創(chuàng)建環(huán)境對(duì)象
env = luasql.mysql()

--連接數(shù)據(jù)庫(kù)
conn = env:connect("數(shù)據(jù)庫(kù)名","用戶(hù)名","密碼","IP地址",端口)

--設(shè)置數(shù)據(jù)庫(kù)的編碼格式
conn:execute"SET NAMES UTF8"

--執(zhí)行數(shù)據(jù)庫(kù)操作
cur = conn:execute("select * from role")

row = cur:fetch({},"a")

--文件對(duì)象的創(chuàng)建
file = io.open("role.txt","w+");

while row do
    var = string.format("%d %s\n", row.id, row.name)

    print(var)

    file:write(var)

    row = cur:fetch(row,"a")
end


file:close()  --關(guān)閉文件對(duì)象
conn:close()  --關(guān)閉數(shù)據(jù)庫(kù)連接
env:close()   --關(guān)閉數(shù)據(jù)庫(kù)環(huán)境


以上內(nèi)容是否對(duì)您有幫助:
在線(xiàn)筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)