此代码上的非对象

时间:2014-08-26 18:47:44

标签: php pdo

    private $dbhost = "localhost";
    private $dbname = "bootfor";
    private $dbuser = "root";
    private $dbpass = "";
    private $dbh;
    public $row;

function __costruct()
        {
            try {
                $this->dbh = new PDO("mysql:host=$this->dbhost;charset=utf8;dbname=$this->dbname", $this->dbuser, $this->dbpass);
                $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
                $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            }

            catch(PDOException $error) {
                print "<br > Error!: " . $error->getMessage() . "<br />";
            }
        }

        public

        function categories()
        {
            $this->dbh->prepare("select categories");
            $this->dbh->execute();
            $this->row = $this->dbh->fetch();
        }

错误:

  

致命错误:在第35行的F:\ index.php中调用非对象的成员函数prepare()

我可能是愚蠢的,但是,为什么这是一个非对象的任何想法?我已经尝试过几百次,但我无法弄明白,我已经解决了这个问题,直到我不记得如何......

1 个答案:

答案 0 :(得分:3)

你错误地__costruct()应该是__construct()