stevire Posted February 16, 2009 Share Posted February 16, 2009 Hey guys, I'm using php with postgreSQL and apache. I have php functions that produce sql statements and run them against the database. Is there anyway to log these sql statements with all the user inputted values? I had this going before, but can't remember how I did it!! Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/145417-php-log-of-output/ Share on other sites More sharing options...
Brian W Posted February 16, 2009 Share Posted February 16, 2009 want to write it to a file, send an email somewhere, or store it in a table? If you want to write it to a file (which makes more since), use something like function logstatement($sql){ $file = "logs/log.log"; $handle = fopen($file, 'a'); fwrite($handle, "\n".$sql, filesize($file)+1000); fclose($handle); } Edit: I added \n onto the write so that the logs would be on their own lines. BTW, there is legal problems with doing this in some situations which mostly stem from what you plan on doing with the data. If it is for trouble shooting or for quality improvement/assurance than you are okay. I'll assume that that is what you plan on using it for... Link to comment https://forums.phpfreaks.com/topic/145417-php-log-of-output/#findComment-763383 Share on other sites More sharing options...
stevire Posted February 16, 2009 Author Share Posted February 16, 2009 That did the trick thanks a mill!! Yeah its all running off my own machine, on the localhost. I thought there was a setting in php.ini/apache config to do this automatically? Link to comment https://forums.phpfreaks.com/topic/145417-php-log-of-output/#findComment-763400 Share on other sites More sharing options...
PFMaBiSmAd Posted February 16, 2009 Share Posted February 16, 2009 The php.ini logging settings apply to php generated errors. For your application to "automatically" do anything, you must write code to cause it to happen. Also see the error_log function on how you can log information in your application program. Link to comment https://forums.phpfreaks.com/topic/145417-php-log-of-output/#findComment-763415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.