使用DBI();
是什么导致此插入失败错误1,SELECT调用工作正常,所以它不是凭据问题.
$dbh = DBI->connect("DBI:mysql:$dbname:$dbhost","$dbuser","$dbpass");
my $sth = $dbh->prepare( "INSERT INTO call_fields VALUES ( ?, ?, ?, ? )" ) or die print "$DBI:errstr";
$sth->execute( "NULL", 0, 0, "testing" ) or die print "er $DBI::errstr";
Run Code Online (Sandbox Code Playgroud)
mysql ver 5.5这是为MSWin32-x64构建的perl 5,版本14,subversion 1(v5.14.1)
注意:此语法正常工作:
$ dbh-> do(q/insert into call_fields values(null,0,0,"testing")/)或者死掉"$ dbh :: errstr";
设置RaiseError连接属性,让DBI进行错误处理.
在SQL NULL值表示为undef在Perl,而不是带引号的字符串NULL.
use strictures;
use DBI qw();
my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost", $dbuser, $dbpass, { RaiseError => 1 });
my $sth = $dbh->prepare('INSERT INTO call_fields VALUES ( ?, ?, ?, ? )');
$sth->execute(undef, 0, 0, 'testing');
Run Code Online (Sandbox Code Playgroud)