ac1982 Posted October 8, 2008 Share Posted October 8, 2008 Hi Is there any php function or another way for capturing all the mysql queries that are send from the user to the server? Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 8, 2008 Share Posted October 8, 2008 I would probably go about it like this. I used an array and just declared it global in the function but personally I would have a logging function that would log the queries rather than just adding them to an array. Anyway this will be a dimensional array that will look like this: $array['select'] = array("first select type query", "second select type query", "etc..."); $array['insert'] = array("first insert type query", "second insert type query", "etc..."); $array['update'] = array("first update type query", "second update type query", "etc..."); <?php $queryLog = array(); $dbconn = someMysqlConnectFunction(); function runQuery($query, $dbconn) { global $queryLog; list($querytype) = explode(" ", strtolower(trim($query))); $queryLog[$querytype][] = $query; return mysql_query($query, $dbconn); } $result = runQuery("select * from tablename where column = 'value'", $dbconn); ?> Quote Link to comment Share on other sites More sharing options...
ac1982 Posted October 8, 2008 Author Share Posted October 8, 2008 Thats one way to do it if you create a site from scratch but I have an existing site and I would like to get all the queries that my existing site sends to the server. Any other ideas? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2008 Share Posted October 8, 2008 Mysql has a query log that logs the date/time, mysql user name, and the actual query. Otherwise you would need to add code to your script at each mysql_query() statement or if you are using a database class, to the common point in the class code that executes a mysql_query() to do what you want. The php error_log() function is intended for this purpose. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.