Discussion Forums
- Topic List
- Most Recent Posts
- Sign In for more options
Hi I want to establish connection with mysql manually in rails so i use DBI.connect("DBI:Mysql:video_devlopment:localhost", "username", "userpaass") but it give me errors how i make this . can one sort this . Thanks
I found the solutions First we have to installed ruby dbi-0.2.0 pack for the mysql Then this work .
I assume you're just doing this with pure Ruby but if you're doing this in Rails, there's a better way:
You don't need DBI to connect to MySQL without ActiveRecord, you can just use the "MySQL/Ruby":http://rubyforge.org/projects/mysql-ruby/ driver Rails uses, avoiding the need to add another dependency to your software.
Standard Ruby, using the mysql gem:
require 'rubygems'
require 'mysql'
db_handle = Mysql.real_connect('localhost', 'user','password','db_name')
Then you can do whatever with db_handle, e.g:
db_handle.query('SELECT * FROM some_stuff')
HTH, Peter
