0

Hi Community!

I have already searched the whole web about this Problem, and I didn't find anything. Maybe you can help...

I want to show the number of all SQL queries I executed to load a web page. It is a very complex system I programmed, and I don't want to count them manually. I use PDO for this, so I can't easily write a function count_query($sql) which increases a counter and return query($sql) I have already tried to write my an "myPDO"-class, extended from PDO, to do this job, but it didn't work.

class myPDO extends PDO{
    var $myOwnCount =0;
    public function __construct($location,$user,$pass)
    {
        parent::__construct($location,$user,$pass);
    } 
    public function exec($q){
        $this->myOwnCount ++;
        return parent::exec($s);
    }
    public function query($q){
        $this->myOwnCount ++;
        return parent::query($s);
    }
}

Gave those Errors:

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\...\functions.php on line 52
Fatal error: Call to a member function fetch() on a non-object in C:\xampp\htdocs\...\index.php on line 69

Thanks for help

Paul

2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by opatut
0

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\...\functions.php on line 52

What is the Code in functions.php on line 52? (the whole function if possible)

Fatal error: Call to a member function fetch() on a non-object in C:\xampp\htdocs\...\index.php on line 69

I think this is caused because you didn't create a instance of the class

$class = new YourClassName();

Or declare fetch as a static public function(), but when you access it you call it like

YourClassName::fetch($arguments_here_if_any);

0

I Create the Object like this:

$dataBase = new myPDO($location, $user, $pass);

If I use PDO instead, it works:

$dataBase = new PDO($location, $user, $pass);

Functions.php around line 52:

$sql = $database->query("SELECT id,title FROM general");
foreach ($sql as $general)
    $generalData[$general["id"]] = $g["title"];

The Problem is that you can use the PDOStatement in foreach like an Array. My class doesn't support this, but it should because it is extended from PDO...

Edited by opatut: n/a

0

$sql = $database->query("SELECT id,title FROM general");
foreach ($sql as $general)
$generalData[$general["id"]] = $g["title"];

Edited, removed!

EDIT: Glad you solved it!

Edited by smartness: n/a

0

I FOUND IT!!!

public function query($q){
     $this->myOwnCount ++;
     return parent::query($s);
}

This cant work! Thanks for helping, but it was - of course - a little mistake.

Paul

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.