Port number isn't required unless you are running your mysqld client on
other port than default.

what is happening when you execute the script?

have you tried connect(...) || die "Cannot connectect to the database
$DBI::errstr\n"; ?

Anton

-----Original Message-----
From: Steve Howard [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 19, 2001 6:28 PM
To: Juan; [EMAIL PROTECTED]
Subject: RE: Connecting to MySQL


Juan,

I don't see location or port # in your connection string. Here is an example
of connecting to MySQL using default MySQL settings for port, and with the
MySQL daemon (service) running on the local machine. You don't have to
format it the same way, but you have to get all the elements into your
connection string:


use DBI;
  my $database_name     = 'intra_data';
  my $location          = 'localhost';
  my $port_num          = '3306'; # This is default for mysql


  # define the location of the sql server.
  my $database          = "DBI:mysql:$database_name:$location:$port_num";
  my $db_user           = "sa";
  my $db_password       = "pass";

  # connect to the sql server.
  my $dbh       = DBI->connect($database,$db_user,$db_password);





The $location and $port_num on the line defining $database are what you seem
to be missing.

Hope this helps,

Steve Howard
-----Original Message-----
From: Juan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 19, 2001 8:10 PM
To: [EMAIL PROTECTED]
Subject: Connecting to MySQL


Hi,

I'm trying to connect MySQL using the following code:

#!/usr/bin/perl -w

use CGI qw(:standard);
use DBI();


print header;
print start_html("mysql");

print h1("Lista de Medicamentos/Cosméticos");


$dbh = DBI->connect("DBI:mysql:fol","fol","passfrr27");
$sth = $dbh->prepare("SELECT CODE,DESCRIPTION FROM PRODUCT LIMIT 0, 30");
$sth->execute or die "Error: ".$sth->errstr();

print p("=====================================");
print p("Number of records: $sth->rows");

while(($cod,$desc) = $sth->fetchrow_array) {
      print "$cod - $desc\n";
}

$dbh->disconnect;


print end_html;


PLEASE!!  What am I doing wrong???

TIA,
Juan.

Reply via email to