Solved

Overload but still call

Posted on 2013-11-08
2
273 Views
Last Modified: 2013-11-09
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
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39633253
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39635642
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question