Daftar dan Belajar Sekarang!

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

foto dikialfin216
6 Kontribusi 0 Coto
1 minggu yang lalu
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);
		}
	}

Jawaban
foto dianarifr
639 Kontribusi 301 Coto
1 minggu yang lalu
coba ganti ke public, begitupun semua function
public function execute()
	{
		$this->stmnt->execute();
	}


Login untuk diksusi di forum sekolah koding