Re: mysql, dbi and help please
On Thu, Dec 21, 2000 at 02:00:14PM -0800, james (home) wrote:
> having installed perl and mysql server etc, I have run my perl script
> available.plx and get the results below
>
> <Snip>
> ADO
> No known data sources
> ExampleP
> dbi:ExampleP:dir=.
> Proxy
> Error: install_driver(Proxy) failed: Can't locate RPC/PlClient.pm i
> mysql
> No known data sources
> </Snip>
>
> Can anyone tell me what I need to do to get dbi talking to mysql, and perl
> talking to them both.
you're not alone.
i too ran into trouble with the mysql modules for dbi NOT
returning 'data sources' info.
#!/usr/bin/perl
use DBI;
$ENV{DBI_USER} = 'userNameHere';
$ENV{DBI_PASS} = 'passwdHere';
@dbms = DBI->available_drivers(1);
foreach $dr( @dbms ) {
print "$dr\n";
@src = ();
eval{ @src = DBI->data_sources( $dr ) };
foreach $src( @src ) {
$ENV{DBI_DSN} = $src;
print "\t$src\n";
$dbh = DBI->connect("$dsn",$ENV{DBI_USER},$ENV{DBI_PASS});
foreach $tbl ( $dbh->tables ) {
print "\t\t$tbl\n";
next; # remove if you wanna see all available fields, too
$sth = eval{ $dbh->prepare("select * from $tbl limit 1") }
# || eval{ $dbh->prepare("select * from $tbl") }
|| next;
eval {
$sth->execute();
@nam = @{ $sth->{NAME} };
@typ = @{ $sth->{TYPE} };
$sth->finish();
while ( ($n = shift(@nam)) && ($t = shift(@typ)) ) {
print "\t\t\t$n : $t (",
join(", ",
map {$_->{'TYPE_NAME'}} $dbh->type_info($typ)
),
")\n";
}
};
}
$dbh->disconnect();
}
}
here's what i get:
ADO
ExampleP
dbi:ExampleP:dir=.
.
..
public_html
.cedit
loghtml
DBI_Pg
ether
cgi-bin
.enlightenment
cablemodem
dns
.lftp
msql
.ssh
.procmail
cgiImages
uninetsolutions
terminfo
.elm
Mail
.mc
.ssh2
.cpan
.gnupg
Multiplex
Pg
dbi:Pg:dbname=admin
id
dbi:Pg:dbname=agf
bo2000
dbi:Pg:dbname=camp
dbi:Pg:dbname=ed
country
courses
currency
edits
edittype
edu
language
medium
programs
ratings
region
students
v_edu
who
dbi:Pg:dbname=puz
active
cust
exp
paid
pay
ponly
puzct
puzno
range
sell
tot
unconf
dbi:Pg:dbname=template1
dbi:Pg:dbname=tharp
folk
projects
Proxy
mysql
i.e. postgres interacts nicely, but the DBI for
mysql doesn't reveal data sources. if you know the
data sources, you can plug them in and all is well,
of course...
my versions are as followes (with superfluousity snipped):
% uname -a
Linux server 2.2.17 #1 Sun Jun 25 09:24:41 EST 2000 i586 unknown
% perl -v
This is perl, version 5.005_03 built for i386-linux
% perl -MDBI -MDBD::mysql -de 1
> v
'DBD/mysql.pm' => '2.0415 from /usr/local/lib/site_perl/i386-linux/DBD/mysql.pm'
'DBI.pm' => '1.13 from /usr/lib/perl5/5.005/i386-linux/DBI.pm'
% mysql -V
mysql Ver 9.38 Distrib 3.22.32, for pc-linux-gnu (i586)
% psql
[PostgreSQL 6.5.3 on i686-pc-linux-gnu, compiled by gcc 2.95.2]
--
will@serensoft.com *** http://www.dontUthink.com/
volunteer to document your experience for next week's
newbies -- http://www.eGroups.com/messages/newbieDoc
Reply to: