[英]How to Connect the Ruby to the Postgresql?
我嘗試將 ruby 連接到 postgres,但它無法連接,顯示錯誤"uninitialized constant PGconn"
。
require "pg"
conn = PGconn.connect("localhost", 5432, "", "", "test1")
res = conn.exec("select * from a;")
PGConn 是錯誤的,名為 pg 的 postrges gem 現在正在使用 PG。
例子:
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.