MySQL, Ruby, DBI connetc problem...help please

S

Sean Armstrong

------=_Part_15700_15620411.1126885995155
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I currently have the MySQL binary for Windows installed. I have ruby under=
=20
both cygwin and windows installed. I can not get the DBI module for either=
=20
ruby version to connect to my mysql database. Here is the code:

require 'dbi' # so far so good

dbh =3D DBI.connect('DBI:Mysql:test', 'testuser', 'testpwd') # here's
where it crashes
from /usr/lib/ruby/site_ruby/1.8/dbi/dbi.rb:499:in `load_driver'
from /usr/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in `_get_full_driver'
from /usr/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in `connect'
from (irb):5

I thought that maybe I had to declare the host so:

dbh =3D DBI.connect('DBI:Mysql:test:.', 'testuser', 'testpwd') # here's
where it crashes
from /usr/lib/ruby/site_ruby/1.8/dbi/dbi.rb:499:in `load_driver'
from /usr/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in `_get_full_driver'
from /usr/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in `connect'
from (irb):5

I thought maybe there was something wrong with the database but the=20
following connects just fine in the terminal:

mysql -u testuser -p -h . test

I can not seem to get the DBI to work with Windows, apparently the ruby=20
modules are only good with Unix and not Windows. Please do not say try=20
mysql-ruby. I can not even get that to compile. I've tried compiling Mysql=
=20
source for the libs but it still refuses to find the mysql libs no matter=
=20
wher I point extcong.rb. So I tried going back to DBI. That is where I stan=
d=20
now. Certainly someone out there has been able to get this module to work=
=20
properly with the MySQL binary install and WinXP?

Thanks:)

SA

--=20
"I can do everything on my Mac that I could do on a PC."
-- Me

------=_Part_15700_15620411.1126885995155--
 
P

Paul

use mysql-administrator & check the
Startup Parameters->Security->Use Old Passwords checkbox
restart mysql server
try again.
 
X

x1

I'm assuming you've got this installed:
http://ruby-dbi.sourceforge.net/

What did I do to get this to work?

start> run> odbcad32

click system dsn, choose add.

Look for MySQL at the bottom.. if it's not there, download and install it:
http://dev.mysql.com/get/Downloads/MyODBC3/MyODBC-3.51.11-2-win.msi/from/pi=
ck

Afer installing it, click add again within the odbcad32 window, and
select the mysql driver..

put in the hostname and db details.. give the connector a name which
you will use with the connection shizza... test the connection then
close..

Create the ruby script to test it..
This example pretty much worked for me:

require 'dbi'

# connect to a datbase
dbh =3D DBI.connect('DBI:Mysql:test', 'testuser', 'testpwd')

puts "selecting..."
sth=3Ddbh.prepare('select * from simple01')
sth.execute

while row=3Dsth.fetch do
p row
end
 
C

Charles Roper

Hello,

I'm new to Ruby (quite new to programming in general) and I've very
much been enjoying reading the posts here, although a lot of it goes
way over my head. Anyway, I was looking for some help connecting to
MySQL on Windows, came across this thread and managed to get a
connection using the MyODBC method. Only thing is, the connection
arguments needs to read thus for ODBC:

dbh = DBI.connect("DBI:ODBC:MyODBCdatasourcename, "user", "pass")

Probably obvious to most folks, but I thought I'd pass it on in the
spirit of sharing :)

One question: what are the disadvantages of using ODBC over a native
driver? Is it just a performance issue?

Cheers,

Charles
 
S

Stefan Schmiedl

One question: what are the disadvantages of using ODBC over a native
driver? Is it just a performance issue?

You might also encounter some limitations of the ODBC driver in use.
There can be features available in the DB server SQL implementation,
which the "generic" ODBC driver simply does/will/can not offer.

s.
 
C

Charles Roper

Many thanks for the reply. Can you offer any examples of what might not
work?

Charles
 
S

Stefan Schmiedl

Many thanks for the reply. Can you offer any examples of what might not
work?

Not off the top of my head, sorry.

What I do remember is that I ran into problems with some
faulty ODBC drivers for Paradox, silently messing up simple joins.
Accessing the same tables via BDE from Delphi (i.e. "natively" worked,
but reading the data failed miserably from each of Ruby, Dolphin Smalltalk
and VB6, too.

On a side note, I've implemented a small access layer to MySQL for
a windows-based Forth environment. Since the C-level API is based on
strings, this was very easy for me as interface implementor.
ODBC offers a much richer set of datatypes, which makes life for the
end user more convenient (you get numbers from number columns).

s.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top