store all your code in MySql
Posted: Wed Aug 04, 2010 11:50 am
I decided I wanted to keep my PHP code in a MySql database. I wanted to record a "modified date/time" for each function. Before using eval() on each function, code is added so that we send input variables that the function received, to the string called $_GLOBALS['dbug'] .
Some possibilities:
-display the code of MyFunction() in an editable text box. display a list of links to the functions that are called by MyFunction(). display a list of links to the functions that call MyFunction();
-optionally send the function's "return" value to the 'dbug' variable.
-sort the 'log of function calls & inputs' that we are putting in 'dbug' so that the most-recently-edited functions show first. so the function you are editing now, automatically shows you what information it is receiving when it is called.
-when you edit a function, copy the old code to a log so you can retrieve old versions of the function.
Some possibilities:
-display the code of MyFunction() in an editable text box. display a list of links to the functions that are called by MyFunction(). display a list of links to the functions that call MyFunction();
-optionally send the function's "return" value to the 'dbug' variable.
-sort the 'log of function calls & inputs' that we are putting in 'dbug' so that the most-recently-edited functions show first. so the function you are editing now, automatically shows you what information it is receiving when it is called.
-when you edit a function, copy the old code to a log so you can retrieve old versions of the function.
Code: Select all
function connectToDb2(){
$con = mysql_connect("localhost","mySqlUserName","thisIsAPassword");
$db_selected = mysql_select_db('testing123');
}
function getFunctions(){
$result=mysql_query("SELECT `time`,`name` FROM `edr`");
for($i = 0;$array[$i]=mysql_fetch_assoc($result);$i++){
$array[$i]=implode("\n",$array[$i]);
$array[$i]=transformFunctionsForDebug($array[$i]);
}
$array = "saveandrespond();\n" . implode("",$array);
eval($array);
//echo "<pre>";print_r(htmlspecialchars($array));echo "</pre>";
}
function transformFunctionsForDebug($function){
$functionTime=leftofdelim($function,"\n");
$function=rightofdelim($function,"\n");
$functionHead=leftofdelim($function,"{");
$functionCode=rightofdelim($function,"{");
$functionName=leftofdelim($functionHead,"(");
$functionName=str_replace("function ","",$functionName);
$vars=rightofdelim($functionHead,"(");
$vars=trim($vars,"()&\$ ");
$vars=explode("$",$vars);
$i=0;
foreach ($vars as $var){
$var = "\$" . trim($var,", &");
$va[$i]=leftofdelim($var,"=");
$i++;
}
$debugCode .= "\$GLOBALS['dbug'].= \"";
$debugCode .= "$functionTime $functionName ";
foreach($va as $var){
if ($var == "\$")continue;
$debugCode .= ltrim($var,"\$ ") . "- \" . print_r(" . $var . ",TRUE) . \" ";
}
$debugCode .= "\";";
return "$functionHead{ $debugCode " . ltrim($functionCode,"{");
}
function leftofdelim($string,$delim){
if ($delimPos=strpos($string,$delim))
$string = substr($string,0,$delimPos);
return $string;
}
function rightofdelim($string,$delim){
if ($delimPos=strpos($string,$delim))
$string = substr($string,$delimPos);
return $string;
}Code: Select all
function setDebug(){
if (!$_POST[0])
$response .= "(no request)";
$response = ("PHP server received this request: $response"
. $_POST[0] . $GLOBALS['dbug']);
$response=str_replace("\n",'\n',$response);
$response=str_replace("\r","",$response);
$response=htmlspecialchars($response);
echo <<<EOD
<script type="text/javascript">
function doMenu2(){
item=document.getElementById("tableChange").selectedIndex;
if (item == 0){
document.getElementById('DivExample').innerHTML = "<p>Table:<input type=\"text\" value=\'Table\' id=\'field1\' />Record Name:<input type=\"text\" value=\'Name\' id=\'field2\' />Relationship:<input type=\"text\" value=\'Relationship\' id=\'field3\' /><input type=\"hidden\" id=\'field4\' /><input type=\"hidden\" id=\'field5\' /><input id=\'Button1\' type=\'button\' value=\'Add Record\' onclick=\"collateSend(\'addRecord\')\" /></p>";
}
else if (item == 1)
{document.getElementById('DivExample').innerHTML = "<p>Table:<input type=\"text\" value=\'Table\' id=\'field1\' />Column Name:<input type=\"text\" value=\'ColumnName\' id=\'field2\' /><input type=\"hidden\" id=\'field3\' /><input type=\"hidden\" id=\'field4\' /><input type=\"hidden\" id=\'field5\' /><input id=\'Button1\' type=\'button\' value=\'Add Column\' onclick=\"collateSend(\'addColumn\')\" /></p>";}
else if (item == 6)
{document.getElementById('DivExample').innerHTML = "<p><textarea COLS=140 WRAP=SOFT ROWS=3>$response</textarea></p>";}
}
</script>
EOD;
}
echo "<p><textarea>$response</textarea></p>";