Fatal error: uncaught error: call to a member function execute() on null

Fatal error: Uncaught Error: Call to a member function execute() on null in C:\xampp\htdocs\project\App\Core\Database.php on line 60 malem smua izin bertanya penyebab itu error apa ya? trus cara fix nya gmna? berikut codingan nya
<?php 

	/**
	 * 
	 */
	class Database
	{
		private $dbh;
		private $stmnt;

		function __construct()
		{
			$dsn = "mysql:dbname=" . DBNAME . ';dbhost=' . DBHOST;
			$option = [
				PDO::ATTR_PERSISTENT => true,
				PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
			];

			try {

				$this->dbh = new PDO($dsn, DBUSER, DBPASS, $option);

			} catch (PDOException $e) {
				die($e->getMessage());
			}
		}

		function query($query)
		{
			$this->stmnt = $this->dbh->prepare($query);
		}

		function bind($parameter, $value, $type=null)
		{
			if (is_null($type)) {
				switch (true) {
					case is_bool($value):
						$type = PDO::PARAM_BOOL;
						break;

					case is_null($value):
						$type = PDO::PARAM_NULL;
						break;

					case is_int($value):
						$type = PDO::PARAM_INT;
						break;
					
					default:
						$type = PDO::PARAM_STR;
						break;
				}
			}

			$this->stmnt->bindValue($parameter, $value, $type);
		}

		function execute()
		{
			$this->stmnt->execute();
		}

		function rowCount()
		{
			return $this->stmnt->rowCount();
		}

		function getAll()
		{
			$this->execute();
			return $this->stmnt->fetchAll(PDO::FETCH_ASSOC);
		}
	}
avatar dikialfin216

Ditanyakan oleh @dikialfin216

6 Kontribusi 0 Poin

Login untuk menanggapi


Jawaban

coba ganti ke public, begitupun semua function
public function execute()
	{
		$this->stmnt->execute();
	}
avatar dianarifr

Dijawab oleh @dianarifr

639 Kontribusi 304 Poin

Login untuk menanggapi


Login untuk gabung berdiskusi