我的代码中有错误:
致命错误:在第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;
}
}
如何解决?
答案 0 :(得分:0)
关于“非对象”的错误在这里是你的问题...数据库对象没有创建开始,因此使用该不存在的对象的后续操作将失败。有关授权的其他信息是您必须修复的...正确授权和连接,然后将创建数据库对象,因此在您使用它时就存在。