Re: Overriding core functions
| From: | Jochem Maas | Date: | Tue, 22 Aug 2006 12:27:13 +0000 |
| Subject: | Re: Overriding core functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240987@lists.php.net to get a copy of this message | ||
Peter Lauri wrote:
> Hi,
>
>
>
> I want to add some functionality when calling the mysql_query():
>
>
>
function my_query($Query) {
//do stuff before
mysql_query($Query);
//do things after
}
// or something like:
class PeteDB {
var $conn;
function PeteDB($db, $usr, $pwd, $etc) {
$this->conn = mysql_connect($db, $usr, $pwd, $etc);
if (!is_resource($this->conn)) die('db is useless'); // trigger_error()
}
function query($qry/*, $args*/) {
// do stuff
$r = mysql_query($qry, $this->conn);
// do more stuff
return $r;
}
}
/*
tada!
hint: always use some kind of wrapper for things like db related functions
(because it allows for stuff like this and, for instance, makes it alot easier to
switch dbs - because you only have to change code in one place, not counting any db-specific
sql floating around your app)
*/
>
>
>
> This would just be for one project where I want to record all Queries and
> the result of them, creating an own logging function.
>
>
>
> I did a lot of Google, but no article that I found that take care of this
> subject.
>
>
>
> /Peter
>
>
>
>
>
>
>
>