Page 1 of 1

Logging database activity

Posted: Wed Aug 23, 2006 4:53 pm
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

Posted: Wed Aug 23, 2006 5:46 pm
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.

Posted: Wed Aug 23, 2006 6:41 pm
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.

Posted: Wed Aug 23, 2006 6:51 pm
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.

Posted: Wed Aug 23, 2006 6:55 pm
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