Re: how am I able to log all sql queries?

From: Robby Russell <rrussell(at)commandprompt(dot)com>
To: sector119(at)mail(dot)ru, pgsql-php(at)postgresql(dot)org
Subject: Re: how am I able to log all sql queries?
Date: 2003-09-22 14:42:04
Message-ID: 3F6F0A3C.1080205@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

sector119(at)mail(dot)ru wrote:
> hi
>
> I want to log all queries which has been executed by my program!
>
> like:
> *user_ip* who run program, and *queries* which has been executed durin
> time that he use this program (my site)
>

PostgreSQL can log it for you, but if you want to do it on a client
basis, I'd create a log table in your db and add a function to your
program that for each time you execute a query, you log the ip and the
sql query to the database table. If you're using pg_query or something
you could create a custom function like so: (don't mind the horrible
php, but you might get the idea I'm trying to show.)

function pg_log_query($ip, $sql) {
# query to insert the sql to the database
pg_query("INSERT INTO logging (ip, sql) VALUES ('$ip', '$sql');

# call the normal pg_query
pg_query($sql);
}

Hope that helps

--
Robby Russell, | Sr. Administrator / Lead Programmer
Command Prompt, Inc. | http://www.commandprompt.com
rrussell(at)commandprompt(dot)com | Telephone: (503) 222.2783

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Sebastiano Cascione 2003-09-22 16:43:01 current connection
Previous Message sector119 2003-09-22 05:04:06 how am I able to log all sql queries?