Hi all,
i heard that prepared statements help u when ever u want to execute a query repeatedly
in such a scenario prepared stmts helps a lot and improves speed also
is it right. if so can i implement them in php
can someone give me any example of how to use prepared statements in php
thanks
how to use prepared statements in php
Page 1 of 14 Replies - 1112 Views - Last Post: 12 September 2008 - 04:40 AM
Replies To: how to use prepared statements in php
#2
Re: how to use prepared statements in php
Posted 11 September 2008 - 10:36 PM
Hi ,
i'm trying the following code to work with prepared stmts
but the above is returning nothing
my table structure is as follows
i have one record as follows
i'm passing $_get['date'] as 1-1-2009..(if i echo it i get 1-1-2009)
so my output should be Happy new year
but i am not getting desired output.i am getting only "higetting"
any help pls...
i'm trying the following code to work with prepared stmts
<?
$remdt=$_GET['date'];
$res="Getting..";
$dbh = new mysqli("localhost", "iamuser", "password", "finddb");
$stmt = $dbh->prepare("SELECT remMsg FROM reminder where remDate = ?");
$stmt->bind_param('s',$remdt);
//print "Hi";
if ($stmt->execute())
{
if ($stmt->fetch()===true)
{
print "Hi";
$stmt->bind_result($res);
printf("%s", $res);
}
else
{
print " U have no reminder on : $remdt";
}
}
else
{
print "Query can not be executed..";
}
?>
but the above is returning nothing
my table structure is as follows
id number remMsg varchar remDate varchar
i have one record as follows
id remMsg remDate 1 Happy new year 1-1-2009
i'm passing $_get['date'] as 1-1-2009..(if i echo it i get 1-1-2009)
so my output should be Happy new year
but i am not getting desired output.i am getting only "higetting"
any help pls...
This post has been edited by kummu4help: 11 September 2008 - 10:41 PM
#3
Re: how to use prepared statements in php
Posted 12 September 2008 - 01:20 AM
don't have time to run through all the code now, but i will over my lunch time.
Had a quick browse over it and noticed this:
if ($stmt->fetch()===true)
which should be:
if ($stmt->fetch()==true)
Had a quick browse over it and noticed this:
if ($stmt->fetch()===true)
which should be:
if ($stmt->fetch()==true)
#4
Re: how to use prepared statements in php
Posted 12 September 2008 - 04:05 AM
Hi all,
thanks for quick reply
particularly pemcconnell. He wil always be there when ever i have a post..
any way i could able to solve my problem
i just changed the following block i.e
as follows
the $stmt->bind_result($res) should be above the $stmt->execute() stmt...
after a big search i found that
any way thanks for all
but can any one point me to a good prepared statement explanation link
i saw one in dic tutorial but it is a bit tough to grasp for me
thanks for quick reply
particularly pemcconnell. He wil always be there when ever i have a post..
any way i could able to solve my problem
i just changed the following block i.e
if ($stmt->execute())
{
if ($stmt->fetch()===true)
{
print "Hi";
$stmt->bind_result($res);
printf("%s", $res);
}
as follows
$stmt->bind_result($res);
if ($stmt->execute())
{
if ($stmt->fetch()===true)
{
print "Hi";
printf("%s", $res);
}
the $stmt->bind_result($res) should be above the $stmt->execute() stmt...
after a big search i found that
any way thanks for all
but can any one point me to a good prepared statement explanation link
i saw one in dic tutorial but it is a bit tough to grasp for me
#5
Re: how to use prepared statements in php
Posted 12 September 2008 - 04:40 AM
There's a bit of coverage on this page:
http://devzone.zend....ode/view/id/686
Seems to break it down quite well. (The prepared statement section is about half way down that page)
Hope that helps
http://devzone.zend....ode/view/id/686
Seems to break it down quite well. (The prepared statement section is about half way down that page)
Hope that helps
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|