2 messages in com.mysql.lists.perlPerl, MySQL and NULL values...
FromSent OnAttachments
Jonas Thorell16 Feb 2002 15:10 
Niño Fision16 Feb 2002 15:31 
Subject:Perl, MySQL and NULL values...
From:Jonas Thorell (jona@bahnhof.se)
Date:02/16/2002 03:10:13 PM
List:com.mysql.lists.perl

I know I'm probably missing something obvious here but...

How do I alter/insert a null value in a database from Perl?

No matter how I do it it always ends up being wrong.

What I've tried to do is the following:

my $sth=$dbh->prepare("insert into customer (id,name,lastname,email) values (null,?,?,?);");

$sth->bind_param(1,$name); $sth->bind_param(2,$lastname); $sth->bind_param(3,$email);

$sth->execute();

$dbh->disconnect();

The variables I get from a webpage, so what I'm trying to accomplish is a cgi-script to add things to a database. Works just fine except that null thing. Oh, and ID is an auto-increment field so that's not a problem.

The email-field is supposedly meant to be null if nothing's entered there but no matter what I'm doing I get an empty string added into that particular field instead, which isn't at at all what I'm after.

So, how do I do substitute the empty string with a null value before committing the execute() call?

Any ideas?

/Jonas