July 27th, 2000, 05:41 PM
i am trying to use DBI to connect to a mysql database.
i used this
but i could not connect.
so i used the funciton DBI->available_drivers() and found that the MySQL driver did not show up.
is this why i could not connect? how do i get the driver onto the server? how can i get this to work?
thanks in advance for reading my post.
July 27th, 2000, 06:38 PM
You go to CPAN and search for MySQL DBD DBI driver. Once you get it, simply follow the instructions inside the tarball and you'll soon get it installed. Its really no big deal...
July 28th, 2000, 07:38 AM
Go to a command line and type:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>perl -MCPAN -e shell[/code]
This will take you into an interactive "shell" to download and install CPAN modules.
At the command prompt you're given, type:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>install DBD::mysql[/code]
The shell will now go out and grab all the appropriate modules and install them for you. Note, if you haven't used the CPAN shell before, you'll be asked a few configuration questions -- ignore the ones you don't understand, and fill in the others. The beauty of the CPAN shell is that it generally goes out and finds all of the dependancies you may need for a module to run, and will grab and build those too, thereby simplifying the whole process.
One note, you may (for some modules) need a C compiler and make program. If you're on Wintel, your easiest option is MS Visual Studio, though there are various ports of the GNU tools kicking around that may work (check out cygwin.com). Naturally, on un*x systems you should have a full set of tools avaiable from GNU or your favourite proprietary vendor.
[This message has been edited by christucker (edited July 29, 2000).]
July 29th, 2000, 06:58 PM
thakns for all the information, im going to try it out. btw, how is DBD used?
July 29th, 2000, 07:49 PM
The DBD is specified in your connect string to the database. It's completely transparent so long as you stick to 'ordinary' (i.e. relatively standardised) SQL (any of your standard SELECT, INSERT, UPDATE, etc. stuff, basically, and most ALTER, CREATE etc.). The DBD (that's DataBase Driver, by the way) is simply an interface between the abstract DBI (DataBase Interface) layer, and the database itself. So, using MySQL, all you need to know about the DBD is that its name is mysql, and so your DBI connect call will be something like:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
my $dbh = DBI->connect('DBI:mysql:mydatabase', $user, $pass, $extra_options);
Most of the time $extra_options won't be used -- if you do need it, it's just a reference to a hash of options like RaiseError. There's loads of info on that in the DBI PODs.
July 30th, 2000, 09:36 AM
That's what I like about it. If you want to move your script from MySQL to, say, ODBC, you just have to change that 1 line of code. Most of the time, anyway...