Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

Overload but still call

Is it possible to overload a function, but still call it?

I want to extend PHP $mysqli->query, where I want to keep a log of the SQL queries used, but then still carry it out, so I know I need to extend the mysqli class, but would like to either disable the ->query in my extended class (so it cant be called), but then in my ->query2 still call the ->query function.

What Ive got soo far which I think is along the right lines is:-
<?php
class MySQLi2 extends MySQLi
{
    public function query  ($query)
    {
        parent::query ("insert into `logger` (`sqlCode`) VALUES ('" . mysql_real_escape_string($query)  . "')");
        return parent::query ($query);
    }
}

Open in new window


Ive only found a few documented sources of using parent:: so think Im using it wrongly.

Any  ideas what Im doing wrong?

Thank you
0
tonelm54
Asked:
tonelm54
  • 2
1 Solution
 
Ray PaseurCommented:
I guess the answer to the title question is "yes" but the term "overload" may be misapplied.  I think your code looks fine, except you would not use mysql_real_escape_string().

Try setting up a couple of temporary tables and testing it.  You'll probably find that you're on firm ground.  If you instantiate the MySQLI2 object, you will want it to call the parent constructor to create the connection.  Something like parent::_construct(...)
0
 
Ray PaseurCommented:
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now