Extending PDO Statement Class

Viewed 11993

Is it possible to extend PHP PDO statement class to add custom methods to it? This would be different from extending the base PDO class. If so, how would one go about doing it since the statement class is only returned when running queries through the PDO class?

4 Answers

If you are using namespaces for your classes you need to add a backslash to your class string.

Without namespace:

$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Custom', array($pdo)));

With namespace:

$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Namespace\Custom', array($pdo)));
Related