CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
DBI can not connect to Mysql

 



photores
Deleted

Mar 26, 2001, 6:08 AM

Post #1 of 4 (1335 views)
DBI can not connect to Mysql Can't Post

Hi, guys!
Please, help.
I write script that use DBI for connecting to Mysql, but I have error:
- "DBI->connect(mail_list:localhost:3306) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) at /var/www/cgi-bin/test.pl line 15
Can't call method "prepare" on an undefined value at /var/www/cgi-bin/test.pl line 17. "-
I try change users access e.t.c., but without results.
Please HELP! :-)

###########################################
#!/usr/bin/perl
################################
use CGI qw(:standard);
use DBI;
use Parse;
my $tpl = new Parse;
use strict;
my $db = param('db');
my $query = param('query');

print "Content-type: text/html\n\n";

if($query) {

my $dbh = DBI->connect("DBI:mysql:$db:localhost:3306");

my $dbs = $dbh->prepare($query);
$dbs->execute;
my $err = $dbh->errstr;
if($err) {
$tpl->{'ERROR'} = "А вот и ошибочка случилась: $err";
$tpl->{'DB'} = $db;
}
}
File is attached.




(This post was edited by photores on Mar 26, 2001, 5:16 AM)


Jasmine
Administrator / Moderator

Mar 26, 2001, 10:03 AM

Post #2 of 4 (1329 views)
Re: DBI can not connect to Mysql [In reply to] Can't Post

I don't see where you're initializing CGI to use param('db').


Code
my $in = CGI->new(); 
my $db = $in->param('db');

Have you tried removing the 3306?

The username/password also isn't being passed to the connect command:


Code
my $dbh = DBI->connect( "dbi:mysql:$db", "username", "password")  
or die "Can't connect to database: $DBI::errstr\n";

Always take advantage of $DBI::errstr -- it returns the complete error string from DBI, so it will tell you why the command failed.



localfilmmaker
stranger

Apr 24, 2001, 3:06 PM

Post #3 of 4 (1306 views)
Re: DBI can not connect to Mysql [In reply to] Can't Post

When you specify

Code
use CGI ':standard';

you import all the functionality of the CGI module without creating a CGI object. I prefer the object oriented method myself, but it works either way. Just like the slogan says, "There's more than one way to do it."
And, yes! Always print out $DBI::errstr if you have DBI problems.


-localfilmmaker
Spencer Christensen
spencer@mecworks.com


Pro_4
User

Apr 24, 2001, 3:10 PM

Post #4 of 4 (1305 views)
Re: DBI can not connect to Mysql [In reply to] Can't Post

hey photores, just wondering what server do you have. I too have a script that uses DBI but my server doesnt let you install need modules. Also is it free??

Thanks :)

Always add fun to Perl
$fun = "fun"; $perl = "Perl";
print " Always add $fun to $perl"; die;

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives