List:General Discussion« Previous MessageNext Message »
From:Adrian Phillips Date:July 19 2000 2:38pm
Subject:Re: Sql Syntax
View as plain text  
>>>>> "Bert" == Bert Beaudin <bertb@stripped> writes:

    Bert> Hello all Im new to Perl, DBI and mysql. Im working on a
    Bert> perlk script to update a table in mysql. I have scripts that
    Bert> insercet and select from the table, but I can not get the
    Bert> syntax correct for the update statment. Below is what I
    Bert> currently using. Any pointers would be great. Thanks in
    Bert> advance.

    Bert> Bert Beaudin bertb@stripped


    Bert> # Connect to the "DB" MySQL database on localhost $dbh =
    Bert> DBI->connect("DBI:mysql:DB:localhost","username","password");

    Bert> # Log and die if we cannot connect
    Bert> &log_and_die($DBI::errstr) unless $dbh;

    Bert> # Create our query string $sql = "UPDATE webcontact"; $sql.=
    Bert> "SET (firstname = '$firstname', lastname = '$lastname',
    Bert> email_address = '$email_address',"; $sql.= "street_address =
    Bert> '$street_address, city = '$city', state = '$state', zip_code
    Bert> = '$zip_code',"; $sql.= "primary_phone = '$primary_phone',
    Bert> secondary_phone = '$secondary_phone', comment =
    Bert> '$comment',"; $sql.= "where ID='$ID')";

    Bert> # Send the SQL, and make sure all is well $sth =
    Bert> $dbh->prepare($sql); &log_and_die($sth->errstr) unless $sth;

    Bert> # Execute the query, and make sure all is well $sth->execute
    Bert> || &log_and_die($sth->err);

Urgh, you placeholders for this :-

$sql = "UPDATE webcontact SET (firstname = ?,lastname = ?, .....)";
my $sth = $dbh->prepare ($sql) or die;
$sth->execute ($firstname,$lastname,....) or die;

Sincerely,

Adrian Phillips

-- 
Your mouse has moved.
Windows NT must be restarted for the change to take effect.
Reboot now?  [OK]
Thread
Sql SyntaxBert Beaudin17 Jul
  • Re: Sql SyntaxAdrian Phillips20 Jul