This is a standard insert example from a DBI manual:
my $query = q{ INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?) }; my $sth = $dbh->prepare($query) or die $dbh->errstr; while (<>) { chomp; my ($product_code, $qty, $price) = split /,/; $sth->execute($product_code, $qty, $price) or die ($query . " " . $dbh->errstr); } $dbh->commit or die $dbh->errstr;
I changed it a bit, so I can see on which error the request ended ( die ($query . " " . $dbh->errstr) ). However, I liked the query with the associated values (how it was executed). How to get it?
Edit
Btw, I found an awkward way to see a query with related values: you have to make a syntax error in the query. For example, if I modify the request above:
my $query = q{ xINSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?) };
I got it back as I wanted:
DBD :: mysql :: st execute failed: you encountered an error in the SQL syntax; check the manual that matches the version of your MySQL server for the correct syntax to use the sample 'xINSERT INTO (product_code, qty, price) VALUES (' 1 ',' 2 ',' 3 ')' on line 1
Sometimes it really helps. At least it's with me.
source share