You're only getting half of what you need. DBI is the "Database Interface" half. The part I think you're missing (based on the error messages you report, and the process you've described) is the DBD -- "Database Driver". Look on PPM or CPAN for DBI::ODBC.
See, much like ODBC, DBI only describes a common set of methods for accessing data stores. You need download the drivers which actually implement those methods. As always, CPAN has your hookup
Once you've got that installed, you can use
to connect to your database. You may need to alter the dbi:ODBC:DSN portion depending on how your database is set up.$dbh = DBI->connect('dbi:ODBC:DSN', 'user', 'password') || die ("Can't + connect to database : ",$DBI::errstr);
Again, notice the die. If this statement dies, there's typically a problem with the statement's syntax, or the database handle ($dbh) is undefined.$sql = $dbh->prepare ("SELECT field FROM table") or die ("Unable t +o prepare statement: ",$DBI::errstr);
This is where the fun happens :
This will set the SQL gnomes scurrying, and stores the result of the statement in $sql.$sql->execute()or die ("Unable to execute get_servertime : ",$DBI: +:errstr);
Now that the results are in, how to read them? It depends. There's several methods of doing so, and each one is detailed in the documentation. My most often used one is
, but there's other methods of doing so. There's a nice hash method which'll store the field names as the hash keys, so you can manipulate$row{fieldname} if that's clearer than working with array elements.@l_row = $sql->fetchrow_array;
When everything's done and said,
to close the database. For further information, see Programming the Perl DBI, and of course, DBI's own POD, which has a synopsis of how to connect and read to a database.$dbh->disconnect
OK?
In reply to (boo) Re: Re: Re: Can't locate DBD/ODBC.pm in @INC
by boo_radley
in thread Can't locate DBD/ODBC.pm in @INC
by Fian
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |