Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBI Connect failed 1

Status
Not open for further replies.

RexJacobus

Programmer
Dec 10, 2001
47
NZ
Apache is running. (I can run HelloWorld.cgi)
MySQL is running and password is correct. (I can query from the cmd line)

Can someone give me a clue why the following code doesn't work?

________________________________
#!/perl/bin/perl <i>(correct path in dev)</i>
print "Content-type: text/html\n\n";
print "**********Connect Test\n";

use DBI;

# Connecting to the database
# Replace DATABASENAME with the name of the database,
# HOSTNAME with the hostname/ip address of the MySQL server.
$drh = DBI->install_driver("mysql");
$dsn = "DBI:mysql:database=homer;host=mysql.secureserver.net";
$dbh = DBI->connect($dsn,"root","simpson");

# Select the data and display to the browser

my $sth = $dbh->prepare("SELECT * FROM players");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}n";
}

$sth->finish();

# Disconnect from the database.

$dbh->disconnect();
_______________________________
When I run this from the cmd line I get

Content-type: text-html
*******************Connect Test

DBI connect('database=homer;host=mysql.secureserver.net','root',... failed:
Can't connect to MySQL server on 'mysql.secureserver.net' (10060) at connecttest.cgi line 12.



Thanks,
Jim
 
I just used DBI myself.

did you install the MySQL driver?

ppm install DBD::mysql

maybe you need to reference the port?

Code:
dsn="DBI:mysql:database=skylightslogs;host=Cphnbdev2;port=3306";
 
By chance is your database on a godaddy server?

There's always a better way. The fun is trying to find it!
 

Thanks Andyfives, it wasn't the port but when I tried your answer it made me realise that if the db was right, and the port was right, then maybe the host was the problem.

Once that occurred to me I realised that this is a dev db and I should be using 'host=localhost'. Duh.

j

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top