How to Get PDO database object to own tag code ?

28 views
Skip to first unread message

snack...@googlemail.com

unread,
Oct 17, 2012, 7:55:41 AM10/17/12
to h2o-temp...@googlegroups.com
Hello,

i try to use the PDO data object in my own tag code but i can not get it to work.
What i can get, is the PDO data object to the Class with creating a instance of the PDO object.
This works in between the "__construct" function.

Now i try to pass the "$this->result" object to the "render" function to add ist to the context part, but with no success.
My "$this->result" object does no more exist when i try to use it in the render function. Why ?

I am not a Professional to OOP so please help,

Any Idea or suggestion to solve this problem ?

Thanks in advance.
Greetings Snacker




class LoadDBdata_Tag extends H2o_Node {
    private $sequence;
    private $result;

    function __construct($argstring, $parser, $pos) {
        $args = h2o_parser::parseArguments($argstring);
        $this->sequence = $args;

        $pdocore = Core::getInstance();
        $oDB = $pdocore->dbh;

        $sql = 'SELECT * FROM table';

        $q = $oDB->query($sql);
        $this->result = $q->fetchAll(PDO::FETCH_OBJ);
    }

    function render($context, $stream) {
        $a = array(
            'result'    => $this->result,
        );

        $context->set('myResults', $a);
    }
}

h2o::addTag('load_data');
Reply all
Reply to author
Forward
0 new messages