Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\xampp\htdocs\joblister\lib\Database.php:32 Stack trace: #0 C:\xampp\htdocs\joblister\lib\job.php(10): Database->query('SELECT jobs.*, ...') #1 C:\xampp\htdocs\joblister\index.php(15): Job->getAllJobs() #2 {main} thrown in C:\xampp\htdocs\joblister\lib\Database.php on line 32 #114

Open
codesmith445 opened this issue Feb 17, 2023 · 1 comment

Comments

@codesmith445
Copy link

host .';dbname='. $this->dbname; // Set Options $options = array ( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ); //PDO INSTANCE try { $this->dbh = new PDO($dsn, $this->user, $this->pass, $options); } catch(PDOException $e) { $this->error = $e->getMessage(); } } public function query($query) { $this->stmt = $this->dbh->prepare($query); } public function bind($param, $value, $type = null) { if(is_null($type)) { switch(true) { case is_int ( $value ) : $type = PDO::PARAM_INT; break; case is_bool ( $value ) : $type = PDO::PARAM_BOOL; break; case is_null ( $value ) : $type = PDO::PARAM_NULL; break; default : $type = PDO::PARAM_STR; } } $this->stmt->bindValue($param, $value, $type); } public function execute() { return $this->stmt->execute(); } public function resultSet() { $this->execute(); return $this->stmt->fetchAll(PDO::FETCH_OBJ); } public function single() { return $this->stmt->fetch(PDO::FETCH_OBJ); } }
@daveh
Copy link
Owner

daveh commented Feb 19, 2023

The error message is saying $this->dbh is null - this happens when it hasn't connected for some reason, probably because of incorrect database credentials (user, password)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants