in reply to DBI selectall_arrayref
In addition to the comments regarding quoting of field names, I wanted to mention one other thing.
Just as you wouldn't dream of opening a file without checking the return value of open to see that the open was successful, you shouldn't just assume that your database operations are successful either, without proper error checking. For example, when you connect to the database:
$dbh = DBI->connect($data_source, $username, $password) or die $DBI::errstr;
Likewise, you need to error check after executing your selectall_arrayref(). This is explained in the POD:
If "RaiseError" is not set and any method except fetchall_arrayref fails then selectall_arrayref will return undef; if fetchall_arrayref fails then it will return with whatever data has been fetched thus far. You should check $sth->err afterwards (or use the RaiseError attribute) to discover if the data is complete or was truncated due to an error.
Also, maybe I'm not getting it, but when you call the connect() method, according to the DBI docs, the install_driver() method is called implicitly if needed. I don't think there's any need to call it yourself, and in fact, if you do call it yourself, calling it after attempting to connect is too late; you would need that driver to be installed before you can connect. I haven't run into any need to use the install_driver() method, so I could be way off, but it seems wrong to be installing the driver after trying to connect to the database.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBI selectall_arrayref
by jeffa (Bishop) on Sep 02, 2004 at 17:18 UTC | |
by davido (Cardinal) on Sep 03, 2004 at 00:04 UTC | |
by jeffa (Bishop) on Sep 03, 2004 at 02:00 UTC | |
|
Re^2: DBI selectall_arrayref
by THuG (Beadle) on Sep 02, 2004 at 17:12 UTC |