Is there a different method of logging onto a DB when using it in a
cgi-bin script rather than running the script from the DOS prompt? This
would indeed explain a not connecting problem. 

My code snippet is:

#########################################################
$db="employees";
$host="localhost";
$port="3306";
$userid="user";
$passwd="pass";
$connectionInfo="DBI:mysql:database=$db;$host:$port";

# make connection to database
#$dbh = DBI->connect($connectionInfo);
$dbh = DBI->connect($connectionInfo,$userid,$passwd);

# prepare and execute query
$query = "INSERT INTO staff (firstName, lastName)
          VALUES ('$firstName', '$lastName')";
$sth = $dbh->prepare($query);
$sth->execute(); 

print "Record inserted into the database";

$sth->finish();

# disconnect from database
$dbh->disconnect; 
#########################################################

- Troy



Ralf Narozny wrote:
> 
> Hello!
> 
> Troy Hickey wrote:
> 
> >Hi,
> >
> >I am pretty new to perl and am currently involved in setting up MySQL
> >database using Perl. My setup includes MySQL running on Win95.
> >I have a simple program which writes a few values to a database. The
> >file works fine when using the Command Line interface and the database
> >gets the correct entries. However when I try to use the script from a
> >web-browser I keep getting the same error message:
> >
> >"Software error:
> >Can't call method "prepare" on an undefined value at
> >/cgi-bin/add_employee.cgi line 33."
> >
> >
> 
> Is it possible that the connect() did not succeed? that would explain
> why $dbh->prepare() would not work.
> 
> >I don't know why this is happening, although I have read as much as I
> >could fine on the net regarding this subject.
> >I'd be grateful for any help.
> >Thanks, -T
> >
> >
> >
> 
> --
> Ralf Narozny
> SPLENDID Internet GmbH & Co KG
> Skandinaviendamm 212, 24109 Kiel, Germany
> fon: +49 431 660 97 0, fax: +49 431 660 97 20
> mailto:[EMAIL PROTECTED], http://www.splendid.de

---------------------------------------------------------------------
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 <mysql-unsubscribe-##L=##[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to