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
@dikialfin216

6 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

1 Jawaban:

coba ganti ke public, begitupun semua function <pre> public function execute() { $this-&gt;stmnt-&gt;execute(); } </pre>

avatar dianarifr
@dianarifr

642 Kontribusi 316 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban