ruby的语法真的是太优雅了!require mysql2# 配置数据源,连接musqlclient = Mysql2::Client.new(host: localhost,username: root,password: root,database: test,encoding: utf8)# Insert 插入state...
ruby的语法真的是太优雅了!
require 'mysql2'
# 配置数据源,连接musql
client = Mysql2::Client.new(
host: 'localhost',
username: 'root',
password: 'root',
database: 'test',
encoding: 'utf8'
)
# Insert 插入
statement = client.prepare("insert into users (email, password) values (?, ?)")
statement.execute("adley123@kk.com", "abc11111")
# Update 更新
statement = client.prepare("update users set email = ? where id= ?")
statement.execute("axs@122.com", 120)
# Delete 删除
statement = client.prepare("delete from users where id = ?")
statement.execute(114)
# Query 查询
results = client.query('SELECT * FROM users')
results.each do |row|
puts row
end
puts results.count
沃梦达教程
本文标题为:ruby 操作mysql crud
基础教程推荐
猜你喜欢
- Go web部署报错panic: listen tcp xxxxxxx:8090: bind: cannot assign requested address 2023-09-05
- asm基础——汇编指令之in/out指令 2023-07-06
- UEFI开发基础HII代码示例 2023-07-07
- R包ggtreeExtra绘制进化树 2022-12-14
- R语言基于Keras的MLP神经网络及环境搭建 2022-12-10
- ruby-on-rails-使用Nginx的Rails的多阶段环境 2023-09-21
- R语言数可视化Split violin plot小提琴图绘制方法 2022-12-10
- R语言-如何将科学计数法表示的数字转化为文本 2022-11-23
- swift 字符串String的使用方法 2023-07-05
- swift版webview加载网页进度条效果 2023-07-05