Object of class PDOStatement could not be converted to string

I’m getting this Catchable fatal error: Object of class PDOStatement could not be converted to string. I’m getting data from one table and inserting into another. I’m trying to find the proper way to convert to string coming from a PDO object. If anyone could point me in the right direction it. Greatly appreciated. Thanks.

Oh, here is some code I’m using:

while ($row = $query->fetch()) {
    $reasons = explode(',', $row->invalid_reason);

    $query_reasons = $handler->prepare("INSERT INTO invalid_reasons (submission_id, invalid_reasons) VALUES(?,?)");

    foreach ($reasons as $r) {
        $query_reasons .= "('{$row->submission_id}','{$r}'),";

    // omit tailing ,
    trim($query_reasons, ',');


I don’t think you can append the additional strings in your foreach() loop to the prepared-statement handle in the way that you do. You define $query_reasons as the handle for the prepared statement, but then try to append strings to the handle. Wouldn’t it be better to just call the execute() method using those as the parameters for your prepared statement?

1 Like

Oh I see you’re correct. I’ll adjust. Thanks for the info.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.