问题
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