--[[
luarocks lua语言的包管理器
luasql https://luarocks.org/
brew install luarocks
luarocks install luasql-mysql 注意此处,如果你是 mariadb,然后要求指定 MYSQL_DIR 参数的时候,
千万不要指到 mariadb 的安装目录,而是要指到一个真正的mysql 安将目录
那是不是不能用 mariadb 呢,也不是,要手动安装一遍
luarocks install luasql-sqlite3
luarocks install luasql-postgres
luarocks install luasql-mysql
luarocks install luasql-sqlite
luarocks install luasql-odbc
]]--
local luasql = require("luasql.mysql");
client = luasql.mysql();
--创建连接
conn=client:connect("lua-test","root","12345678","127.0.0.1",3306); --数据库名,用户名,密码,IP,端口
if conn == nil then
print("连接失败");
os.exit();
end
--select
rs=conn:execute("select * from user_list order by id desc");
row = rs:fetch({},"a");
while row do
print(row.id,row.name,row.age);
row = rs:fetch(row,"a");
end
--insert
--rs=conn:execute("insert into user_list (name,age)values('def',456)");
--print(rs);
--update
rs=conn:execute("update user_list set name='DEF',age=789 where id<=4");
print(rs);
--delete
rs=conn:execute("delete from user_list where id=4");
print(rs);
conn:close();
client:close();
Lua + mysql 实战代码
HuntFalcon2023-08-20 14:58
相关推荐
随风飘的云18 小时前
mysql的innodb引擎对可重复读做了那些优化,可以避免幻读于眠牧北4 天前
MySQL的锁类型,表锁,行锁,MVCC中所使用的临键锁Turnip12026 天前
深度解析:为什么简单的数据库"写操作"会在 MySQL 中卡住?郑州光合科技余经理6 天前
代码展示:PHP搭建海外版外卖系统源码解析feifeigo1236 天前
matlab画图工具加号36 天前
windows系统下mysql多源数据库同步部署シ風箏6 天前
MySQL【部署 04】Docker部署 MySQL8.0.32 版本(网盘镜像及启动命令分享)dustcell.6 天前
haproxy七层代理norlan_jame6 天前
C-PHY与D-PHY差异多恩Stone6 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系