【发布时间】:2014-08-07 04:27:55
【问题描述】:
我是 PHP 新手,我正在尝试创建一个具有内部连接功能的数据库类,但出现此错误:
在第 10 行的 C:\xampp\htdocs\world\index.php 中的非对象上调用成员函数 InnerJoin()
我的代码:
<?php
class DB {
private static $_link = null,
$_host = "127.0.0.1",
$_pass = "",
$_dbname = "mundo",
$_user = "root",
$_charset = "utf8";
private $_pdo,
$_query,
$_count = 0,
$_error = false,
$_results;
private function __construct() {
$this->_pdo = new PDO("mysql:host=".self::$_host.";dbname=".self::$_dbname,self::$_user,self::$_pass);
}
public static function getLink() {
if(!isset(self::$_link)) {
self::$_link = new DB();
}
return self::$_link;
}
public function Get($table) {
return $this->_query = "SELECT * FROM ".$table;
}
public function Go() {
if($this->_query = $this->_pdo->prepare($sql)) {
echo "prepared";
}
}
public function InnerJoin($table1, $column1, $table2, $column2){
return $this->_query = $this->_query." INNER JOIN ".$table2." ON ".$table1.".".$column1." = ".$table2.".".$column2;
}
}
?>
在我的 index.php 中有这个:
<?php
$DB = DB::getLink()->Get("paises")->InnerJoin("paises","Id_Continente","Continentes","Id_Continente")->Go();
?>
希望你能帮帮我,谢谢
【问题讨论】: