Solved

Overload but still call

Posted on 2013-11-08
2
259 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
  • 2
2 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now