I am cutting my teeth on Perl so please be gentle.
If I am still asking where the power switch is in about a month, by all means please read me the riot act at that point.
At home, I have downloaded both Apache 2.0 and mySQL to my Windows XP Prof PC.
I would like to do some CGI and am not getting a short script to recognize my 'system' (not user) ODBC datasource.
Not to get too clever as you have to crawl before you can walk, walk before you can run, I am at a crawl!
The script is short and sweet balks at the DBI->connect statement:
********
#! c:/usr/bin/perl.exe
use DBI;
my $dbh = DBI->connect('DBI:ODBC:mysql_test', 'user_name', 'user_password');
$sth = $dbh->prepare('select * from customer');
$sth->execute;
while (($id,$name) = $sth->fetchrow_array) {
print "Customer Id: $id\n",
"Name: $name\n";
}
$sth->finish;
$dbh->disconnect;
********
with verbiage:
"Can't connect(DBI:ODBC:mysql_test user_name user_password), no database driver specified and DBI_DSN env var not set at dbdemo_test.pl line 9"
I have the service started for mySQL and manually created the table and manually added a couple of rows.
I've tested the datasource in Windows ODBC Administrator and 'mysql_test' is ok.
If I can get this puppy jump started, I would like to start doing some HTML CGI to the backend database.
Any ideas on what I may be missing?
I am becoming hooked on this stuff, hence my handle.
Thanks in advance for any help you can provide!
For starters, I forgot that reinstalled mySQL and so the user/password was not in the admin user table!
Ok, I know where the power switch is now. Good.
I still though could not get a connect with the DBD:ODBC driver.
However, when I changed it to use the mysql driver connect syntax it worked:
/*************
#! c:/usr/bin/perl.exe
use DBI;
my $dbh = DBI->connect("DBI:mysql:database=mysql;host=localhost;port=3306",
"root","",{'RaiseError' => 1});
#my $dbh = DBI->connect("DBI:ODBC:mysql_test","root",""[smilestopper]);
$sth = $dbh->prepare('select * from test.customer');
$sth->execute;
while (($id,$name) = $sth->fetchrow_array) {
print "Customer Id: $id\n",
"Name: $name\n";
}
$sth->finish;
$dbh->disconnect;
************/
I should be able to use the ODBC driver should I not?
At least I can do my CGI.pm stuff now.
Ok, then. Enough of my nattering. Thanks for lending an ear and have a great day!
If you absolutely need to use ODBC with MySQL, there's a Windows ODBC driver for MySQL available at mysql.com You can connect to that driver from DBI using ODBC data source, but seriously, I can't think of any reason for this.
If you look closely at the code, you'll note that there is a pound sign '#' in front of the connect statement that has the ODBC declarative and the correct syntax directly on the next line above uses the mySQL driver you mention.
I am now endeavoring to use ActiveState's Perl with CGI and DBI/Informix in a BRIO.Portal Hospital Healthcare environment.
We'll see how it goes.
Thanks very much for your response and the clarification!
(You were the only one who cared enough to do so. Although my submission was not a 'real' CGI forum question, so I understand the lack of response.)
Regards,
perl_junky