1

我的代码中有错误:

致命错误:在第 47 行对 ... 中的非对象调用成员函数 query()

第 47 行:

$query = $this->link->query("SELECT * FROM links ORDER BY DESC");

完整代码:

<?php

    class Manage{
        public $link;

        function __construct() {
            include_once 'class_database.php';
            $conn = new database;
            $this->link = $conn->connect();

            return $this->link;
        }

        function getData($table_name, $id=null){
            if(isset($id)){
                $query = $this->link->query("SELECT * FROM $table_name");
            }else{
                $query = $this->link->query("SELECT * FROM $table_name ORDER BY id ASC");
            }
            $rowCount = $query->rowCount();
            if($rowCount >=1)
            {
                $query->setFetchMode(PDO::FETCH_ASSOC);
                $result = $query->fetchAll();
            }
            else{
                $result = 0;
            }
            return $result;
        }

        function insertData($table_name, $fields_name, $bind_param, $field_values){
            $query = $this->link->prepare("INSERT INTO $table_name ($fields_name) VALUES      ($bind_param)");
            $query->execute($field_values);

            $rowCount = $query->rowCount();
            return $rowCount();
        }

        function deleteData($table_name, $id){
            $query = $this->link->query("DELETE FROM $table_name WHERE id = '$id'");
            $rowCount = $query->rowCount();
            return $rowCount;
        }

        function selectLinks(){
            $query = $this->link->query("SELECT * FROM links ORDER BY DESC");
            $rowCount = $query->rowCount();

            if($rowCount >=1)
            {
                $query->setFetchMode(PDO::FETCH_ASSOC);
                $result = $query->fetchAll();
            }
            else{
                $result = 0;
            }
            return $result;
        }
    }

怎么修?

4

1 回答 1

0

关于“非对象”的错误是您的问题......数据库对象不是从一开始就创建的,因此对该不存在对象的后续操作将失败。您有关授权的附加信息是您必须修复的...正确授权并连接,然后将创建数据库对象,因此在您使用它时存在。

于 2012-06-02T21:37:00.663 回答