problems in using DBI

懵懂的女人 提交于 2019-12-23 01:52:59

问题


I'm new to all this this stuff. I'm trying to execute the following code

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();

print outputs nothing. Can you tell me what am I doing wrong?

Thank you in advance!


回答1:


You said in one of the comments that you had an @ in the value. If you're having a quoting issue, you should use a placeholder. Let the database driver handle the quoting issues for you:

my $sth = $dbh->prepare("select id from table where field = ?");
$sth->execute($some_value);


来源:https://stackoverflow.com/questions/9565978/problems-in-using-dbi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!