0

我正在尝试运行以下 ruby​​ 程序

require 'rubygems'
require 'mysql'
db = Mysql.new('local','root','','')
st_qry = db.query("SELECT * FROM `notification` ORDER BY notification_id DESC ")
puts ("There were #{st_qry.num_rows} rows returned.")

当我通过终端执行此代码时,我收到以下错误消息:

joe.fleck$ ruby mysql_req.rb 
mysql_req.rb:4:in `initialize': wrong number of arguments (4 for 0) (ArgumentError)
from mysql_req.rb:4:in `new'
from mysql_req.rb:4

我不知道如何解决这个问题。我必须通过这个命令安装 mysql:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include

因为普通命令(sudo gem install mysql)会出错并且无法安装。

我也试过卸载和安装mysql。我尝试了mysql2,当我尝试执行程序时它出错了。

有谁知道如何解决这个问题?

MacBook Pro,OS X 版本 10.8.2

$ gem list
*** LOCAL GEMS ***
addressable (2.3.2)
builder (3.1.3)
childprocess (0.3.5)
cucumber (1.2.1)
diff-lcs (1.1.3)
fastercsv (1.5.5)
ffi (1.1.5)
gherkin (2.11.3)
json (1.7.5)
libwebsocket (0.1.5)
multi_json (1.3.6)
mysql (2.8.1)
pkg-config (1.1.4)
rb-appscript (0.6.1)
rubygems-update (1.8.24)
rubyzip (0.9.9)
safariwatir (0.4.0)
selenium-webdriver (2.25.0)
shoes (3.0.1)
watir-webdriver (0.6.1)
4

0 回答 0