On 1/26/07, James <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've been playing around with using DBI instead of ActiveRecord 'cause
> I just love to beat myself up! ;) Is this an okay way to do this, or
> is there any other more creative ways?
The code looks like it'll *work*, but you're not going to get much of
a performance boost over regular ActiveRecord -- esp. since you
reconnect to the database for each query!
Try this:
---
class DB
def self.dbh
@dbh ||= DBI.connect('DBI:Mysql:dbname', 'username', 'password')
end
end
---
That way, your connection will only be established once per model
class, and will stay open between requests. Alternately, you could set
@@dbh instead of @dbh, which would open just one connection for all
your model classes, but you might have problems handling multiple
simultaneous requests through a single active database handle.
-Lennon
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list