After spending sometime with the other perl monks here is my revised version of the same function above... please let me know what you think
sub InsertProspect
{
# Get the new prospect
my $prospect = shift;
# Connect to the database
my $dbh = DBI->connect('DBI:mysql:menagerie', 'menagerie') or die
+DBI->errstr;
# Insert the new prospect in the database
my $sth = $dbh->prepare("INSERT INTO prospect VALUES (NULL, ?, ?,
+?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
# Execute the statement
$sth->execute($prospect->name, $prospect->address,
$prospect->address2, $prospect->state,
$prospect->city, $prospect->phone,
$prospect->phone2, $prospect->phone3,
$prospect->phone4, $prospect->phoneType,
$prospect->phone2Type, $prospect->phone3Type,
$prospect->phone4, $prospect->email,
$prospect->url, $prospect->interestLevel,
$prospect->designFirm, $prospect->hostingFirm,
$prospect->companyName) or die DBI->errstr;
# Lets get the prospect id that we just added back
$sth = $dbh->prepare("SELECT last_insert_id() from prospect");
$sth->execute or die DBI->errstr;
my @id = $sth->fetchrow_array;
my $ID = $id[0];
# Return the new prospects ID
return $ID;
}
-- rogueFalcon
Why do you people insist on doing things sdrawkcab?
|