note 88282 deleted from function.mysql-query by philip

From: Date: Fri, 04 Sep 2015 19:22:44 +0000
Subject: note 88282 deleted from function.mysql-query by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203657@lists.php.net to get a copy of this message
Note Submitter: girishpadia at gmail dot com ---- Hello all, I have extended mysql_query function to have more flexibility. It is a php file say "run_query.php". Include this file in your php application. To use this follow this steps. 1) Create a table in mysql with the following structure. CREATE TABLE errorlog ( query varchar(5000) default NULL, error varchar(5000) default NULL ) 2) Create a php file and paste following code. Save the file (say file name is run_query.php). <?php function mysql_query_($query) { include "pass1.php"; $curdate = date("d-m-Y H:i:s"); if(mysql_query($query) == true) { if(substr(strtoupper($query),0,6) == 'INSERT' || substr(strtoupper($query),0,5) == 'UPDATE' || substr(strtoupper($query),0,5) == 'DELETE') { $fp=fopen("trans.sql","a"); if($fp==null) { die("File cannot be opened. Try again !!!"); } $printline = "/* $curdate : */ $query ;"; fprintf($fp,"\r\n%s",$printline); fclose($fp); return true; } else { return mysql_query($query); } } else { $error = mysql_error(); $error = addslashes($error); $query = addslashes($query); mysql_query("insert into errorlog values('$query','$error')"); return false; } } ?> 3) Include this file in your any php application. 4) Use mysql_query_ function instead of mysql_query function. Advantages. 1) You can log query and error in your database table (errorlog). 2) A sql file created/appendended whenever any Data manipulation query is fired. So you can have a complete transaction log in query format. 3) This sql file will help you in "point in time recovery" in case of the database is crashed. Your views ,comments and updation in this function are welcome. girishpadia@gmail.com

« previous php.notes (#203657) next »