我正在尝试将数据插入MySQL数据库:
$response = $client->fql->query(
query => '
SELECT name, email, birthday, username, first_name, last_name, pic
FROM user
WHERE uid = me()
',
);
print join "\n Name:", sort map { $_->{name} } @$response;
$dbh->do("
INSERT INTO Users(SNo,Name,Email,Birthday,UserName,FirstName,LastName)
VALUES(1,
sort map { $_->{name} } @$response,
'imm\@gmail.com',
'1987/12/10',
'imm',
'imm',
'Dee')
");
$dbh->disconnect();
在一行中使用了mysql查询。
上面的print语句正确打印名称,但为什么上面的sql insert语句不起作用?
我连接数据库,之后我收到了值,浏览器中的打印工作正常。
为什么mysql语句不接受该值? 插入数据库时不起作用?
答案 0 :(得分:1)
您应该查看the official doc
特别是这个:
# INSERT some data into 'foo'. We are using $dbh->quote() for
# quoting the name.
$dbh->do("INSERT INTO foo VALUES (1, " . $dbh->quote("Tim") . ")");
# Same thing, but using placeholders
$dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen");