Question

I've been toying with PDO to try and make a default return class for results, and also make this the default behaviour in general.

This lead me to discover that I need to extend PDOStatement so that it sets my default class upon instantiation.

There are no obvious errors in the code.

When I create the PDO instance in the DB wrapper, I set the DB handle to use my extended statement class and pass through the class name as a parameter of the results class. I would usually use stdClass but instead, I've made a simple class that extends ArrayObject.

$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_CLASS);
$pdo->setAttribute(
    PDO::ATTR_STATEMENT_CLASS,
    array(
        'DatabaseStatement',
         array('DatabaseRow')
    )
);

This all looks and seems okay, but I get the following error:

SQLSTATE[HY000]: General error: Invalid class name (should be a string)

This isn't the best error message and doesn't really provide any information as to what or where the error is happening, but I believe this is due to the segment above, as once I remove that section, it doesn't issue that error anymore.

Hopefully someone can give me a direction to head in, as I've been Google/SO-ing for some time now, but alas, to no avail.

Thank you in advance, feel free to ask for more information if what I've provided isn't enough :]

Was it helpful?

Solution

sigh

Well, I've fixed the issue. One of my functions was overwriting a parameter in one of my methods in the extended PDOStatement class to null, thus causing my custom row class to be replaced. Oooops.

That was such a simple thing to miss. Amazing what you notice when leaving a project for a short period then coming back to it! Hahaha.... Ugh, embarrassed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top