[unixODBC-support] unixODBC, MySQL & Perl

Alan Smith alan at d-sol.co.uk
Sun Feb 20 14:01:55 GMT 2005


Hi,

I'm having trouble getting unixODBC to work with Perl. With isql I can connect 
to my database and run SQL queries but with Perl I get a segfault.

odbc.ini=
[TestDSN]
Description = MySQL ODBC Database
Driver = MyODBC
Server = localhost
Database = test
Port = 
Socket = 
Option = 3
Stmt = 

odbcinst.ini=
[ODBC]
Trace = Yes
TraceFile = /tmp/sql.log
ForceTrace = Yes
Pooling = No
[MyODBC]
Description = ODBC Driver for MySQL
Driver = /usr/lib/unixODBC/libmyodbc3.so
Setup = /usr/lib/unixODBC/libodbcmyS.so.1
UsageCount = 1
CPTimeout = 
CPReuse = 
Option =

If I run this perl script:
#!/usr/bin/perl
# Go
use DBI();
use strict;

my @drivers = DBI->available_drivers;
print join(", ", @drivers), "\n";
my $d = join("", @drivers);
print "DBD::ODBC ";
print "not " if ($d !~ /ODBC/);
print "installed\n";
my @dsns = DBI->data_sources('ODBC');
foreach my $d (@dsns) {
        print "$d\n";
}
my $dbh = DBI->connect('DBI:ODBC:TestDSN', 'demo', 'password');
$dbh->disconnect if ($dbh);
exit (0);

I get the following output:
CSV, DBM, ExampleP, File, ODBC, Proxy, Sponge, mysql
DBD::ODBC installed
DBI:ODBC:TestDSN
Segmentation fault

If I deliberately mis-type the user name with dmo instead of demo I get the 
following output:
CSV, DBM, ExampleP, File, ODBC, Proxy, Sponge, mysql
DBD::ODBC installed
DBI:ODBC:TestDSN
DBI connect('TestDSN','dmo',...) failed: [unixODBC][MySQL][ODBC 3.51 
Driver]Access denied for user: 'dmo at localhost' (Using password: YES) 
(SQL-HY000)(DBD: db_login/SQLConnect err=-1) at ../odbc_test.pl line 21

If instead of using unixODBC I use the mysql driver thus:
my $dbh = DBI->connect('DBI:mysql:test', 'demo', 'password');

The script successfully connects to the database.

Can anybody help?

Thanks,

Alan Smith.





More information about the unixODBC-support mailing list