类PDO的对象无法转换为字符串


Object of class PDO could not be converted to string

标题中引用的错误(显然)发生在第33行。顺便说一句,如果你对我如何优化这一点有任何建议,或者只是一般性的建议,我会洗耳恭听。谢谢

这是代码:

<?php
error_reporting(E_ALL);
require('config.php');
$filename = htmlentities($_FILES['file']['name']);
$tmpname = $_FILES['file']['tmp_name'];
$filesize = $_FILES['file']['size'];
$filetype = $_FILES['file']['type'];    
$file = $_FILES['file'];
class connect {
    public function dbConnect($host, $user, $pass, $dbname) {
        try {
            global $dbcon;
            $dbcon = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
        }
        catch (PDOException $e) {
            print $e->getMessage();
        }
    }
}
class upload Extends connect {
    public function uploadFile($dbcon, $filename, $filesize, $filetype, $file) {
        if ($filesize > 2000000) {
            echo "File too large!";
        }
        elseif ($filesize <= 2000000) {
            $stmt = $dbcon->prepare("INSERT INTO upload (name, type, size, content) VALUES (?, ?, ?, ?)");
            $stmt->$dbcon->bindParam(1, $filename);
            $stmt->$dbcon->bindParam(2, $filetype);
            $stmt->$dbcon->bindParam(3, $filesize);
            $stmt->$dbcon->bindParam(4, $file);
            $stmt->$dbcon->execute();
            $stmt->$dbcon->close();
            echo "File uploaded!";
        }
        else {
            echo "Unexpected error! Please try again!";
        }
    }
}
$con = new connect;
$con->dbConnect($host, $user, $pass, $dbname);
$exec = new upload;
$exec->uploadFile($dbcon, $filename, $filesize, $filetype, $file);

您应该使用:

$stmt->bindParam();

$stmt->$dbcon->bindParam()中删除$dbcon