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


基础教程推荐
猜你喜欢
- R语言入门使用RStudio制作包含Rcpp代码的R包 2022-12-05
- 汇编语言:比较指令、跳转指令、JCC的使用 2023-07-06
- 详解swift中xcworkspace多项目管理 2023-07-05
- ruby – 如何使用Nginx,Passenger,Sinatra创建多个位置 2023-09-20
- R语言的一个加法函数使用介绍 2022-11-14
- R语言向量下标和子集的使用 2022-12-10
- 深入探究Golang中log标准库的使用 2023-07-25
- 解决R语言中install_github中无法安装遇到的问题 2022-11-26
- 如何将mysql数据库文件连接到Rails应用程序上的本地ruby 2023-09-21
- R语言因子型数值转数值型的操作 2022-11-23