使用DBI
连接到MySQL数据库后,我启用了trace这样的
$dbh->trace('SQL|DBD');
然后在此之后我的SQL查询打印两次:
>count_params statement SELECT table1.ID ID, table1.LinkID LinkID, Link.ID Link_ID FROM `table1` `table1` JOIN `table2` `Link` ON `table1`.`LinkID` = `Link`.`ID` WHERE table1.ID = ?
>parse_params statement SELECT table1.ID ID, table1.LinkID LinkID, Link.ID Link_ID FROM `table1` `table1` JOIN `table2` `Link` ON `table1`.`LinkID` = `Link`.`ID` WHERE table1.ID = ?
如何只打印每个执行的SQL语句一次?
答案 0 :(得分:2)
如何只打印每个执行的SQL语句一次?
你做不到。 Add-Type -AssemblyName System.Drawing
$filename ="$env:userprofile\Desktop\px95.png"
$bitmap = New-Object System.Drawing.Bitmap 95,19
$barBlendWidth = 20
$start = $bitmap.Width - $barBlendWidth
$mid = $bitmap.Width - ( 0 + $barBlendWidth / 2 )
$p0 = New-Object System.Drawing.Point($start, 10 )
$p1 = New-Object System.Drawing.Point($mid, 10 )
$p2 = New-Object System.Drawing.Point($bitmap.Width, 10 )
$fromColour = [System.Drawing.Color]::FromArgb(255, 144, 238, 144)
$midColour = [System.Drawing.Color]::FromArgb(255, 255, 255, 255)
$toColour = [System.Drawing.Color]::FromArgb(255, 255, 255, 70)
$brushBG = [System.Drawing.Brushes]::LightGreen
$brush1 = New-Object System.Drawing.Drawing2D.LinearGradientBrush($p0, $p1, $fromColour, $midColour)
$brush2 = New-Object System.Drawing.Drawing2D.LinearGradientBrush($p1 , $p2, $midColour, $toColour)
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
$graphics.FillRectangle($brushBG, 0, 0, $bitmap.Width, $bitmap.Height)
$graphics.FillRectangle($brush1 , $start ,0,$barBlendWidth,$bitmap.Height)
$graphics.FillRectangle($brush2 , $mid ,0,$barBlendWidth,$bitmap.Height)
$bitmap.Save($filename)
和count_params
是DBD :: mysql用于在客户端上模拟预准备语句的内部函数。执行预准备语句时都会调用它们。
count_params
并包含以下内容:
parse_params
执行语句时会调用 parse_params
并包含以下内容:
if (DBIc_DBISTATE(imp_xxh)->debug >= 2)
PerlIO_printf(DBIc_LOGPIO(imp_xxh), ">count_params statement %s\n", statement);
两者的逻辑是相同的,所以它可以是全部或全部。