Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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 调用非静态方法时出错_Php_Mysqli - Fatal编程技术网

Php 调用非静态方法时出错

Php 调用非静态方法时出错,php,mysqli,Php,Mysqli,我正在调用一个私有非静态方法,那么为什么会出现此错误: 致命错误: 在第43行的/var/www/html/coexplore/html5BoilerPlate/php/LocalImage.php中不在对象上下文中时使用$this 非静态地调用方法。例如,如果调用YourClass::upload(),则将其替换为类似$class=newyourclass()$类->上传()以非静态方式调用方法。例如,如果调用YourClass::upload(),则将其替换为类似$class=newyour

我正在调用一个私有非静态方法,那么为什么会出现此错误:

致命错误: 在第43行的/var/www/html/coexplore/html5BoilerPlate/php/LocalImage.php中不在对象上下文中时使用
$this


非静态地调用方法。例如,如果调用
YourClass::upload()
,则将其替换为类似
$class=newyourclass()$类->上传()

以非静态方式调用方法。例如,如果调用
YourClass::upload()
,则将其替换为类似
$class=newyourclass()$类->上传()

请解释原因好吗?请解释原因好吗?请提供类
数据库连接的代码问题在于如何调用
upload
。显示调用它的代码。如果这看起来很琐碎,很抱歉,但在您的示例中只有29行。你能发布第43行吗?…提供类
数据库连接的代码问题在于你如何调用
上传
。显示调用它的代码。如果这看起来很琐碎,很抱歉,但在您的示例中只有29行。你能发43行吗?。。。
public  function upload() {

    try {
        $database_connect = new DatabaseConnect();
        $connection = $database_connect->getConnection();

        $this->populate_database($connection); //line 43
        $connection->close();

        return true;

    } catch (Exception $exp) {
        echo $exp->getMessage();
        return false;

    }

}

private function populate_database(mysqli $connection){
    $query = "insert into bases (img_url) values ($this->image_name)";
    $result = $connection->query($query);

    if (!$result) die($connection->error);

    if (!$this->update_linked_table($connection)) {
        echo "linked table not updated";
    }
}