求助!!

shubenn 2002-05-14 03:39:05
我在学习perl终于都这样一个问题:
$test_string = 1;
use DBI;
my $dbh=DBI->connect("DBI:mysql:passwd","zhao","1119")
|| die "Cannot connect:\n";
$sth=$dbh->prepare('select * from user_password where username=$test_string')
|| die "Cannot prepare:$dbh->errstr\n";
$rc=$sth->execute || die "Cannot execute:$dbh->errstr\n";
这样编译就会有错:DBD::mysql::st execute failed: Unknown column '$test_string' in 'where clause' at test.pl line 14.
而直接改成$sth=$dbh->prepare('select * from user_password where username=1') 就可以查询了.
请教要如何才能在sql语言中引用变量的值($test_string).
谢谢!!



...全文
42 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shubenn 2002-05-14
  • 打赏
  • 举报
回复
谢谢各位!!
beckheng 2002-05-14
  • 打赏
  • 举报
回复
變量的替換插入﹐這么快就看到DBI也太急進了吧﹖
Linus2000 2002-05-14
  • 打赏
  • 举报
回复
$query="select * from user_password where username='$test_string'"
$sth=$dbh->prepare($query);

2,203

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 CGI
社区管理员
  • CGI社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧