Friday, December 28, 2007
Field mushrooms with rucola
Preparation time: 30-40min
Served with bread.
## generate INSERT query SELECT CONCAT('INSERT INTO ',table_name,' (',GROUP_CONCAT( column_name SEPARATOR ',' ),') VALUES (',GROUP_CONCAT( "'$POST_",column_name,"'" SEPARATOR ',' ),')') AS insert_query FROM information_schema.COLUMNS WHERE table_name = 'table' AND TABLE_SCHEMA = 'database'; ## generate UPDATE query SELECT CONCAT('UPDATE ',table_name,' SET ',GROUP_CONCAT( column_name,"='$POST_",column_name,"'" SEPARATOR ',' )) AS update_query FROM information_schema.COLUMNS WHERE table_name = 'table' AND TABLE_SCHEMA = 'database';I save a lot of time using this, not even saying about the typing mistakes I usually do by writing it manually.
INSERT INTO simpletable (id,date,rating) VALUES ('$POST_id','$POST_date','$POST_rating') UPDATE simpletable SET id='$POST_id',date='$POST_date',rating='$POST_rating'
find . -iname "*.php" -exec php comp.php {} \; find . -iname "*.js" -exec php comp.php {} \;script:
// here document terminator $here_document = "END"; error_reporting(0); if(ereg($argv[0],$argv[1])) exit(); function cleanup($line){ $line = preg_replace('/(^|\s)\/\/(.*)\n/','',$line); // remove line comments // comment $line = preg_replace('/(\t|\r|\n)/','',$line); // remove new lines \n, tabs and \r return $line; } $lines = file($argv[1]); echo $argv[1]." "; echo "lines: ".count($lines)." -> "; foreach ($lines as $line) { if(ereg($here_document,$line) && ereg("<<<",$line)) $out.= cleanup($line)."\n"; else if(ereg("$here_document;",$line)) $out.= "\n".cleanup($line)."\n"; else $out.= trim(cleanup($line))." "; } $out = preg_replace('/(\/\*[\s\S]*?\*\/)/', '', $out); // remove multi-line comments /* */ file_put_contents($argv[1],trim($out)); // store back to file echo count(file($argv[1]))."\n";Source: comp.php.txt