dtnwm4807 2014-08-26 18:47
浏览 36

此代码上的非对象

    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();
        }

Error:

Fatal error: Call to a member function prepare() on a non-object in F:\index.php on line 35

I am probably being stupid but, any ideas as to why this is a non-object? I've tried looking at it a few hundred times but I can't figure it out, I've fixed this issue before I just can't remember how...

  • 写回答

1条回答 默认 最新

  • douzhuan1467 2014-08-26 18:52
    关注

    You mispelled __costruct() where it should be __construct()

    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算