Ok, this is the Perl script:
#!/usr/bin/perl
use DBI;
$dbh = DBI->connect("dbd:mysql:test","username","password") or die "Error!";
$sth = $dbh->prepare("select * from test");
@res = $sth->fetchrow_array;
$all = join('',@res);
print $all;
$sth->finish;
$dbh->disconnect;
The error I get when connecting running the Perl script is:
Can't connect(dbd:mysql:test username password), no database driver specified and DBI_DSN env var not set at test.pl line 5.
Any ideas?
I really appreciate your help,
Ralph :) | [reply] |
perldoc DBD::mysql
That being said, your DSN passed to connect isn't
properly configured. DBD::mysql requires a different syntax
in the connect statement requiring hostname and database
instead of simply naming the database you wish to use.
Assuming the mysql-server is on the same box as the
script, try:
$dbh = DBI->connect("dbi:mysql:database=test;hostname=localhost", "username", "password", {RaiseError => 1});
The RaiseError is just good use of available attributes
of the DBI. Read perldoc DBI for more and what
they do.
ALL HAIL BRAK!!!
| [reply] [d/l] [select] |
Hi.
I just discovered that the problem was in putting 'dbd:mysql:test', instead of 'dbi:mysql:test'. Still, it's kind of weird how on my other pc it actually worked when using 'dbd'.
Thanks to all for the great help,
Ralph :) | [reply] |
Hi.
I'll post the code later today, cause I'm not at my computer now.
Ralph :) | [reply] |
Hi.
I've tried Psycho's solution, but it still doesn't work. Keep returning the same error.
Any other ideas?
Ralph :) | [reply] |
Can you paste in the exact error message and your code? it sounds like a typo somewhere, but without seeing your code and the error, I can't say for sure what's happening.
/\/\averick | [reply] |
Yes, lots of ideas! :-)
But, seriously, we can't help you without seeing what you are doing.
Post some code and the complete error message and it will be much easier for us to help. | [reply] |