Logging database activity

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Logging database activity

Post by pedrotuga »

I am codding an algoritm that uses the database as input and output.
I need to keep a log at least of all the queries. Afected rows and errors would be cool as well.

I would like the logs to be saved in a textfile.

One solution i thoght about is creating a wraper for mysql_query() that writes the query and the error ( if exists ) to the file. then use allways that function, mysql_query_w() for instance...

I remember when i used oracle it was possible to output a report after each instruction... is it anyway i can get that report ( it's equivalente for mysql ) into php?

thx in advance
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

One solution i thoght about is creating a wraper for mysql_query() that writes the query and the error ( if exists ) to the file. then use allways that function, mysql_query_w() for instance...
Sounds good to me. Make a class out of it.
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Post by pedrotuga »

Ok... this is something in wich php is not so complete already... maybe in version 5...

I thought about storing the following information for each query:

a timestamp
query string
affected rows
error message

in the database, then run a script to dump it to a text file...

but before i will have a look at mysql log files.

php is great, i love it and i am one of the big defensors of it, but i see what experienced programmers mean when they point some lack of features on php. Well... actually this might be a mysql issue.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

What you want to do you will have to write yourself. Post back if you have any specific problems doing it.
but i see what experienced programmers mean when they point some lack of features on php.
Never heard that one before.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

MySQL has several logs that it can generate if you tell it to, but it is done in the configuration file or at start up.

http://dev.mysql.com/doc/refman/4.1/en/log-files.html
Post Reply