Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing the query after binding parameters

Status
Not open for further replies.

dionsis

Technical User
Dec 29, 2005
3
IE
hey im looking to find out how to print a query back after binding the parameters to the query

$sql contains a query with placeholders

$sth = $package->prepare($sql);
$sth->bind_param(1, $a);
$sth->bind_param(2, $b);
$sth->bind_param(3, $c);
$sth->bind_param(4, $d);
$sth->execute;

once the 4 paramters are bound to the query, i want to put the fully formed query into a variable

any help?
 
I dont think it works that way.

What you could do is..
replace the "?" with the bind parameters in the query and then place it in a variable.
 
does the sth->execute(); not execute the bound query?
surely for it to do that it must know the query is correct form and should have a copy of the query it ran in its meta data somewhere

apologies if this sounds stupid im only new to perl

could you show me an example replace ? with parameter code

thanks for the reply
 
also bearing in mind that i would need to replace 4 ?'s
with 4 different variables
 
well..

my $sql = qq[ select * from data
where cond1 = ?
and cond2 = ?];

print $sql;

print "\n";
my $a = "temp";
my $b = "du";

$sql =~ s/\?/$a/;
$sql =~ s/\?/$b/;

print "\n $sql";

OUTPUT:
select * from data
where cond1 = ?
and cond2 = ?

select * from data
where cond1 = temp
and cond2 = du






 
I always run into problems when my $query has stmnts on diff lines i.e

select * from table
where cond1 = x
and cond2 = y ---> Never seems to work form me.

$x = $ARGV[0]; --> If from Command Line.
chomp ($x);
$y = $ARGV[1];
chomp ($y);

So, my queries look like this: (I test the query out before copy/paste wihtoug new lines)

my $query = qq {select * from table \" where cond1 = $a and cond2 = $b \"};

print "$query";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top