Question about PDO

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Question about PDO

Post by spamyboy »

Code: Select all

 
$result_a   = $db->prepare("SELECT ... WHERE `static_id`= :statistic_page ... ;");
        foreach ($result as $row) {
            $result_a->bindParam(':statistic_page', $row['statistic_page'], PDO::PARAM_INT);
            $result_a->execute();
            $result_a   = $result_a->fetch();
 

Code: Select all

Fatal error: Call to a member function bindParam() on a non-object in C:\Program Files\Zend\Apache2\htdocs\gcms\module\backend\statistic\admin.statistic.php on line 62
If I change it to:

Code: Select all

 
        foreach ($result as $row) {
                       $result_a    = $db->prepare("SELECT ... WHERE `static_id`= :statistic_page ... ;");
            $result_a->bindParam(':statistic_page', $row['statistic_page'], PDO::PARAM_INT);
            $result_a->execute();
            $result_a   = $result_a->fetch();
 
But then I don't see no use of using prepare and others statements.
What would be the correct solution to solve this task?
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Question about PDO

Post by novice4eva »

Code: Select all

 
 $result_a   = $db->prepare("SELECT ... WHERE `static_id`= :statistic_page ... ;");
         foreach ($result as $row) {
             $result_a->bindParam(':statistic_page', $row['statistic_page'], PDO::PARAM_INT);
             $result_a->execute();
             $result_a   = $result_a->fetch();/*DO NOT DO THIS, RATHER DO*/
             $data = $result_a->fetch();
 
$result_a is supposed to be prepared statement, you have in the loop replaced it with some sting result.

Cheers
:drunk:
Post Reply