I need to know if PDO extension I wrote is valid both syntactically and semantically. I've been var_dumping() my connection variables and while the variables are being passed to the constructor (with correct values), I'm not able to actually fetch anything from my database.
I've researched the PDO class on the PHP manual and from what I've uncovered the class I'm using is nearly identical to the extension class given in the examples section of the wiki page.
Here's my code:
class DBConnector extends PDO { private $host; private $username; private $password; private $db; private $dns; public function __construct($host, $username, $password, $db) { $this->host = $host; $this->username = $username; $this->password = $password; $this->db = $db; $this->dns = "mysql:dbname=".$this->db.";host=".$host; $connection = parent::__construct($this->dns, $this->username, $this->password); } } And here's a test query which returns an array with...nothing inside of it. There is data within the database, so obviously something isn't correct.
function testQuery() { global $connection; $query = " SELECT * FROM users "; $stmt = $connection->prepare($query); $result = $stmt->fetchAll(); } Am I doing something wrong?