[英]How to Connect the Ruby to the Postgresql?
I try to connect The ruby to the postgres, but it cannot connecting ,it shows an error "uninitialized constant PGconn"
.我尝试将 ruby 连接到 postgres,但它无法连接,显示错误"uninitialized constant PGconn"
。
require "pg"
conn = PGconn.connect("localhost", 5432, "", "", "test1")
res = conn.exec("select * from a;")
PGConn is wrong, the postrges gem called pg is using PG now. PGConn 是错误的,名为 pg 的 postrges gem 现在正在使用 PG。
Example:例子:
require 'pg'
conn = PG.connect( dbname: 'sales' )
conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
result.each do |row|
puts row.values_at('procpid', 'usename', 'current_query')
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.