Re: Need help connecting to local database with mysql

2002-12-23 Thread Bill Lovett
Hi. I noticed a couple of weird things with your script:

- The error DBI-connect(myd) failed: Couldn't connect to... is 
happening I think because 'DBI:mysqlPP:myd' is in single quotes when you 
call DBI-connect, and the syntax seems off. Maybe you'll have better 
success if you follow the syntax shown on this page:

http://search.cpan.org/author/OYAMA/DBD-mysqlPP-0.03/mysqlPP.pm#EXAMPLE

- You have this line:

  my $sth = $dbh-prepare($sql)

Before you've defined the $sql variable. The usual procedure is to 
define your sql first, then prepare it if necessary (which I don't think 
you need to in this case), execute the query, and then loop through the 
results.

- You have

  my @row;
$event=($row[0]);


Before you do an database stuff, so all those variables are just being 
set to empty strings.

Lastly, do you really need to use mysqlPP? My understanding of that 
module is that it's more situations when you can't get regular DBI to 
work. If DBI is an option, you might be better off with that:

http://search.cpan.org/author/TIMB/DBI-1.32/DBI.pm

-bill


Melissa Stranzl wrote:
Hi all:


I am sending a perl program I am trying to run which
doesn't connect to the database. The error message is
at the bottom of the e-mail. I think the program is
going to the sock file and not TCP/IP and I don't know
how to change this, but I'm not sure whether this is
the error, so any help is much appreciated. 
Happy holidays.

MVS.
 


#!/usr/bin/perl -w
package DBD::mysqlPP;
use CGI':standard','-noDebug';

#feo4.pl

my @row;
 $event=($row[0]);
 $location=($row[1]);
 $time=param($row[2]);
 $price=param($row[3]);
 $description=param($row[4]);
 $contact=param($row[5]);
 $day=param($row[6]);

use DBI;


my $dbh= DBI-connect ('DBI:mysqlPP:myd', 'umvs',
'umvs') ||die Could not connect to database:
.DBI-errstr;

print hello;
my $sth = $dbh-prepare($sql)
or die Can't prepare $sql: $dbh-errstr\n;

my $sql=INSERT INTO event VALUES ('$location',
'$time', '$description', '$price', '$day', '$event',
'$contact');
 $sth-execute();
if (my $sth-SQL($sql)){
print SQL failed;
exit();
}


#my @row;
while(@row = my $sth-fetchrow_array()) {
   print
qw($row[0]\t$row[1]\t$row[2]\n\t$row[3]\n\t$row[4]\n\t$row[5]\n\t$row[6]\n);
}


 $sth-close();
 $sth-finish();
$dbh-disconnect();


This is the error message I get when I compile the
program:

DBI-connect(myd) failed: Couldn't connect to
/tmp/mysql.sock:  at C:/Perl/site/
lib/DBD/mysqlPP.pm line 109
 at feo4.pl line 19
Could not connect to database: Couldn't connect to
/tmp/mysql.sock:  at C:/Perl/
site/lib/DBD/mysqlPP.pm line 109
(in cleanup) Can't call method close on an
undefined value at C:/Perl/
site/lib/DBD/mysqlPP.pm line 274.


-
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Need help connecting to local database with mysql

2002-12-22 Thread Melissa Stranzl
Hi all:


I am sending a perl program I am trying to run which
doesn't connect to the database. The error message is
at the bottom of the e-mail. I think the program is
going to the sock file and not TCP/IP and I don't know
how to change this, but I'm not sure whether this is
the error, so any help is much appreciated. 
Happy holidays.

MVS.
 


#!/usr/bin/perl -w
package DBD::mysqlPP;
use CGI':standard','-noDebug';

#feo4.pl

my @row;
 $event=($row[0]);
 $location=($row[1]);
 $time=param($row[2]);
 $price=param($row[3]);
 $description=param($row[4]);
 $contact=param($row[5]);
 $day=param($row[6]);

use DBI;


my $dbh= DBI-connect ('DBI:mysqlPP:myd', 'umvs',
'umvs') ||die Could not connect to database:
.DBI-errstr;

print hello;
my $sth = $dbh-prepare($sql)
or die Can't prepare $sql: $dbh-errstr\n;

my $sql=INSERT INTO event VALUES ('$location',
'$time', '$description', '$price', '$day', '$event',
'$contact');
 $sth-execute();
if (my $sth-SQL($sql)){
print SQL failed;
exit();
}


#my @row;
while(@row = my $sth-fetchrow_array()) {
   print
qw($row[0]\t$row[1]\t$row[2]\n\t$row[3]\n\t$row[4]\n\t$row[5]\n\t$row[6]\n);
}


 $sth-close();
 $sth-finish();
$dbh-disconnect();


This is the error message I get when I compile the
program:

DBI-connect(myd) failed: Couldn't connect to
/tmp/mysql.sock:  at C:/Perl/site/
lib/DBD/mysqlPP.pm line 109
 at feo4.pl line 19
Could not connect to database: Couldn't connect to
/tmp/mysql.sock:  at C:/Perl/
site/lib/DBD/mysqlPP.pm line 109
(in cleanup) Can't call method close on an
undefined value at C:/Perl/
site/lib/DBD/mysqlPP.pm line 274.


Thanks again.


__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php