I'm not trying to create my own PDO class, just extend it so I can insert a try catch statement in my own execute function (myexecute) so I do not have to write the code every time.
Firstly, is this a good ideas? or should I just scrap it?
so I want this:
$DB = new Database ( HOST, DB, USER, PASS );
$query = $DB->prepare("INSERT * FROM books WHERE title = :title");
$query->bindParam( ':title', $_POST['title'] );
$query->myexecute();
if there was a problem my function (myexecute) would sort the error handling the problem is Im getting this error:
Fatal error: Call to undefined method PDOStatement::myexecute()
Any ideas what Im doing wrong?
class Database extends PDO
{
private $dbh;
private $error;
private $total;
private $p_query;
public function __construct($hostname,$dbname,$username,$password)
{
try
{
$dsn = 'mysql:host='.$hostname.';dbname='.$dbname;
parent::__construct($dsn, $username, $password);
}
catch(PDOException $e)
{
echo "DataBase Error: Connection error.<br>".$e->getMessage();
exit;
}
}
public function myexecute()
{
try
{
return parent::execute();
}
catch (PDOException $e)
{
echo "DataBase Error: The user could not be added.<br>".$e->getMessage();
exit;
}
catch (Exception $e)
{
echo "General Error: The user could not be added.<br>".$e->getMessage();
exit;
}
}
}