SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Location
    Uk
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PDO prepared statement error

    I am failing to understand what the error means in this case:

    Basically i just wanted to try and use different fetch modes - ModelAbstractObject.php

    PHP Code:
    line 22: public function find($id)
    line 23: {
    line 24:        $sql "SELECT * FROM $this->table WHERE id=:id";
    line 25:        $sth $this->dbh->prepare($sql));
    line 26:       $sth->bindParam(':id'$idPDO::PARAM_INT);
    line 27:        $sth->setFetchMode(PDO::FETCH_OBJ);
    line 28:        $sth->execute();
    line 29:        return $sth->fetchAll();
    line 30: } 
    Error:


    Code:
    Catchable fatal error: Object of class Closure could not be converted to string in core/ModelAbstractObject.php on line 28

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Location
    Uk
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sorted the problem.

    What happened is that the parameter $id was being returned by a closure from another class and clearly PDO must have problems with closure - not sure either - but as soon as i returned the $id normally, it worked just fine. So there is the tip: "never return parameter from closure to be used with PDO" ... made that one by myself


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •