0
<?php
    class poll{

        private $db = " " ;
        //private 

        public function __construct($dbConnection){
            $this->$db = $dbConnection;
        }




        public function getPollData(){
            $sql = "SELECT poll_question,yes,no FROM poll WHERE poll_id = 1";

            $statement = $this->$db->prepare($sql);

            $statement->execute();

            $pollData = $statement->fetchData();

            return $pollData;
            }
    }

?>

this is my code,and when i tried to execute on my local host its return error like this :Notice: Undefined variable:

db in /Applications/XAMPP/xamppfiles/htdocs/poll/models/Poll.class.php on line 8

Fatal error: Cannot access empty property in /Applications/XAMPP/xamppfiles/htdocs/poll/models/Poll.class.php on line 8

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98

0 Answers0