Tag: database connection

无法使用gem“pg”从我的Ruby脚本连接到Postgres(pg)数据库(这不是rails,只是纯粹的ruby)

我为我的Mac OSX机器下载了postgres.app。 我有一个rails应用程序已连接并使用postgres应用程序附带的postgres数据库。 现在我正在编写一个纯Ruby测试脚本(Not Rails,纯Ruby,甚至不是Active Record)来尝试连接到postgres数据库实例。 这些是我设置它的步骤 1) ran this command on the terminal: gem install pg — –with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config 2) Added this code to the test script: #!/usr/bin/env ruby #encoding: utf-8 require “pg” @conn = PG.connect( :dbname => ‘oData’, :user => ‘am’, :password => ”) @conn.exec(“CREATE TABLE programs (id serial NOT NULL, name character varying(255);”); […]