简体   繁体   中英

Fatal error: Uncaught Error: Object of class PDOStatement could not be converted to string

if (isset($_POST['pf1'])) {
    try {
        $stmt = $conn->prepare( "UPDATE t1
                SET pref1 = :pf1, 
                WHERE id = 1 ");
        $stmt->bindParam(':pf1', $_POST['pf1']);
        $stmt->execute();
        echo "pf1";

    } catch(PDOException $e) {
        echo $stmt . "<br>" . $e->getMessage();
    }
}

It gives error:

Fatal error: Uncaught Error: Object of class PDOStatement could not be converted to string

I want to update data to db. But it gives me error of PDO exception.

I don't know what's the issue is any help is appreciated.

I think this could be because it ends up in your catch .

It then says echo $stmt. "<br>". $e->getMessage(); echo $stmt. "<br>". $e->getMessage(); . You are trying to echo $stmt (being an Object of class PDOStatement). You cannot echo an Object.

Try var_dump($stmt); to check if the above is true. If that's the case, simply remove the echo of $stmt and you should be good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM