note 88282 added to function.mysql-query

From: Date: Mon, 19 Jan 2009 07:01:12 +0000
Subject: note 88282 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-149434@lists.php.net to get a copy of this message
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 ---- Server IP: 59.162.86.33 Probable Submitter: 202.160.174.4 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/88282 Del: integrated -- https://master.php.net/note/delete/88282/integrated Del: useless -- https://master.php.net/note/delete/88282/useless Del: bad code -- https://master.php.net/note/delete/88282/bad+code Del: spam -- https://master.php.net/note/delete/88282/spam Del: non-english -- https://master.php.net/note/delete/88282/non-english Del: in docs -- https://master.php.net/note/delete/88282/in+docs Del: other reasons-- https://master.php.net/note/delete/88282 Reject -- https://master.php.net/note/reject/88282 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149434) next »