4

So I have this extremely simplified snippet:

@cmd_arry = ("Bob Newhart", "54");
$sqlCmd = "UPDATE foobar SET name = ?, age = ?";
$sth = $dbh->prepare( $sqlCmd);
$resultCnt = $sth->execute( @cmd_arry);
if( my $errMsg = $dbh->errstr) {
  $what_actually_executed = <what?>

Question: how can I retrieve the statement AS EXECUTED ie after data-binding has occurred? I'd like a way to capture the actual statement executed, bound values included, if something goes wrong.

4

1 回答 1

6

你问:

如何在发生数据绑定之后检索语句 AS EXECUTED 即?

一般你不能。大多数非玩具 RDBMS 将执行绑定服务器端,而不是客户端,并且大多数非玩具 perl DBD 驱动程序将利用这一点。检查数据库服务器的日志。

但是,DBI 的跟踪功能可能会为您提供足够的帮助。祝你好运。

更新

user4035 在评论中链接到一个相关的perlmonks 线程,该线程提供了所需绑定变量插值的模拟。

于 2013-07-22T20:13:50.617 回答