我尝试将ruby连接到postgres,但无法连接,显示错误"uninitialized constant PGconn"。
"uninitialized constant PGconn"
require "pg" conn = PGconn.connect("localhost", 5432, "", "", "test1") res = conn.exec("select * from a;")
字符串
jc3wubiy1#
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
5rgfhyps2#
或者:
require 'pg' pg_connection = PG::Connection.new(host: 'localhost', user: 'postgres', password: 'postgres')
字符串Connection.new文档。
Connection.new
2条答案
按热度按时间jc3wubiy1#
PGConn是错误的,称为pg的postrges gem现在正在使用PG。
范例:
字符串
5rgfhyps2#
或者:
字符串
Connection.new
文档。