akosibumblebee Posted November 12, 2017 Share Posted November 12, 2017 Can anyone please help me te resolve my issue. I have a parent class which is my database config. A child class which I am calling on my script. Did I miss something ? Here is my code sir: The parent class class myPDO{ private $dbh; private $error; private $stmt; public function connect(){ $dsn = "mysql:host=localhost;dbname=testdb;"; $options = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ); try{ $this->dbh = new PDO($dsn, 'username', 'passwd', $options); } catch(PDOException $e){ $this->error = $e->getMessage(); return null; } } public function query($sql){ $this->stmt = $this->dbh->prepare($sql); } public function fetch_assoc(){ return $this->stmt->fetchAll(PDO::FETCH_ASSOC); } } child class class myChild extends myPDO { public function getMe($myId){ myPDO::connect(); $sql = "SELECT * FROM table WHERE id = '$myId'"; myPDO::query($sql); $row = myPDO::fetch_assoc(); return $row; } } $myId = 1; $myChild = new myChild; $row = $myChild->getMe($myId); print_r($row); // returns empty Am I missing something? It gives me the result as empty but there is a date on the table with that id. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 12, 2017 Share Posted November 12, 2017 PHP should have presented you with multiple warnings about your code. Find your php.ini, change the settings error_reporting = -1 display_errors = onthen restart your web server and try your code again. Quote Link to comment Share on other sites More sharing options...
akosibumblebee Posted November 12, 2017 Author Share Posted November 12, 2017 PHP should have presented you with multiple warnings about your code. Find your php.ini, change the settings error_reporting = -1 display_errors = onthen restart your web server and try your code again. thanks - the issue is not executing the query Quote Link to comment Share on other sites More sharing options...
requinix Posted November 12, 2017 Share Posted November 12, 2017 Well yeah, I know that. The point is that the assorted errors PHP gave you are an indication as to what you need to fix. So I want to make sure you can see those errors. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.