我对这些东西都是新手。我正在尝试执行以下代码
use DBI;
my $dsn = 'DBI:mysql:db:localhost';
my $db_user_name = 'root';
my $db_password = '*******';
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
my $sth = $dbh->prepare("select id from table where field = 'value'");
$sth->execute();
($id) = $sth->fetchrow_array();
print "id is $id";
$sth->finish();
打印输出什么都没有。你能告诉我我做错了什么吗?
提前谢谢!
答案 0 :(得分:6)
您在其中一条评论中说,您的值中包含@
。如果您有引用问题,则应使用占位符。让数据库驱动程序为您处理引用问题:
my $sth = $dbh->prepare("select id from table where field = ?");
$sth->execute($some_value);