I can’t use the PDO class methods from my own pdo_connection class, with or without extends PDO, it doesn’t work properly.
Class pdo_connection {
//connection create
private $dbhost = "127.0.0.1";
private $dbname = "db";
private $dbuser = "user";
private $dbpass = "pass";
public function __construct() {
return $db = new PDO('mysql:host=' . $this->dbhost . ';dbname=' . $this->dbname, $this->dbuser, $this->dbpass);
}
}
And then when I create the object:
require("api/pdo.connection.class.php");
$db = new pdo_connection();
$db->exec("SET NAMES utf8");
I can’t use exec, because is not a method of pdo_connection class, but I want to use the methods of PDO that is created in the pdo_connection class.
If you want to be able to use
pdo_connectionlike that, you will have to extend PDO.Example:
Then, inside that class, in
__construct, useparent::__construct:This is the class that I made that uses that method: [link]
Usage: