使用DBI时遇到的问题 [英] problems in using DBI

查看:106
本文介绍了使用DBI时遇到的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对所有这些东西都是陌生的。我正在尝试执行以下代码

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不输出任何内容。您能告诉我我在做什么错吗?

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

谢谢您!

推荐答案

您在评论之一中说,您的值中有 @ 。如果您遇到报价问题,则应使用占位符。让数据库驱动程序为您处理引用问题:

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

这篇关于使用DBI时遇到的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆