Page 1 of 1

Question about PDO

Posted: Fri Oct 31, 2008 4:25 pm
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?

Re: Question about PDO

Posted: Wed Nov 05, 2008 4:35 am
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: