0
       <?php

// Forum Configuration
define('DB_HOST','localhost'); // Database Hostname
define('DB_USER','root'); // Database Username
define('DB_PASSWORD',''); // Database Password
define('DB_NAME','ultraforum'); // Database Name
define('WEB_NAME','Website Name'); // Website Name
define('WEB_TITLE','Website Title'); // Website Title

// Do not modify anything under this line :)

    class db {

    var $dbhost;
    var $dbuser;
    var $dbpassword;
    var $dbname;
    var $query;

        function connect() {

            $this->db = 
                new mysqli($this->dbhost, $this->dbuser, $this->dbpassword, $this->dbname);

        }

        function __construct() {
            $this->dbhost = DB_HOST;
            $this->dbuser = DB_USER;
            $this->dbpassword = DB_PASSWORD;
            $this->dbname = DB_NAME;
        }

    }

    $con = new db;
    $con->connect();
    $con->query("SELECT * FROM topics");

仍然不起作用,并给我一个错误致命错误:在第 39 行调用 C:\wamp\www\CodeCanyon\Ultra Forum\core\Config.php 中的未定义方法 db::query()

我刚开始使用 php 面向对象编程,我创建了连接类(使用mySQLi),但我仍然不明白如何运行查询?

4

2 回答 2

0
$con = new db;
$con->connect();
$con->db->query("SELECT * FROM topics");

但是这个类似乎还没有什么用。

于 2013-08-04T09:29:40.120 回答
0

尝试这个

   $con->db->query("SELECT * FROM topics");
于 2013-08-04T09:29:59.163 回答