Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对非对象调用成员函数InnerJoin()_Php_Database_Class - Fatal编程技术网

Php 对非对象调用成员函数InnerJoin()

Php 对非对象调用成员函数InnerJoin(),php,database,class,Php,Database,Class,我是PHP新手,我正在尝试创建一个具有内部连接功能的数据库类,但遇到以下错误: 对第10行C:\xampp\htdocs\world\index.php中的非对象调用成员函数InnerJoin() 我的代码: <?php class DB { private static $_link = null, $_host = "127.0.0.1", $_pass = "", $_dbname = "m

我是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();
?>


我希望您能帮助我,谢谢

,因为您正在从
Get
函数返回
$this->\u query
,因为它需要返回完整的对象才能再次使用它

public function Get($table) {
    $this->_query = "SELECT * FROM ".$table;
    return $this;
}
欲了解更多详情,请阅读

在一条指令中有3个方法调用。。。当每个函数返回必须调用下一个函数的对象时,这没有问题

但这不是在这里发生的

getLink()
初始化对象数据库并重新调用它,因此下一步是ok:

DB->Get("paises")
如果赋值
$this->\u query=“SELECT*FROM”。$table成功。。。当你失败时:

1->InnerJoin

试着不要一次做所有的事情,检查返回值并相应地构造下一步。

他返回的是布尔值,而不是_query我只需要返回$this而不是$this->\u query,我已经用解决方案更新了问题您无法更新问题的答案。如果这个答案对你有帮助的话,那就是为了帮助未来的用户。我已经回到你原来的问题。现在没有要更新的内容。享受编码!!我只需要返回$this而不是$this->\u查询,我已经用解决方案更新了问题
1->InnerJoin