At 21:52, 19990727, Rich Bowen wrote:
>Richard Reina wrote:
>>
>> Can someone send me a very simple perl script that connects to a mysql
>> database and modifies a table.
>
------ ADD ------
#!/PATH-TO-PERL/perl
-----------------
>>use DBI;
>>use strict;
>>my $dbh = DBI->connect('DBI:mysql:database', 'username',
>> 'password');
>die "connect failed: $DBI::errstr" unless $dbh;
>>my $sth = $dbh->prepare("insert into tablename
>> (fname,lname,email)
>> values
>> ('Rich','Bowen','junkmail@stripped')
>die "prepare failed:", $dbh->errstr unless $sth;
>>$sth->execute;
>$sth->execute or die "execute failed:", $sth->errstr;
--------- ADD -------
$sth->finish;
---------------------
>>$dbh->disconnect;
If you are disconnecting your database handle, you should always first
finish any open statement handles. I believe if you use the "-w"
flag in "#!/usr/bin/perl" it'll warn you about that.