PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 12, 2019 10:31 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Wed Aug 04, 2010 11:50 am 
Offline
Forum Newbie

Joined: Wed Jul 21, 2010 3:40 pm
Posts: 5
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.



Syntax: [ Download ] [ Hide ]
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;
}

Syntax: [ Download ] [ Hide ]
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>";
 


Last edited by julianb on Wed Aug 11, 2010 3:15 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Wed Aug 04, 2010 5:58 pm 
Offline
DevNet Master
User avatar

Joined: Sun Jan 21, 2007 12:06 am
Posts: 4135
Is this supposed to be a development tool, or do you plan to implement this a live feature? I'm pretty sure this functionality already exists in some form or another... SVN comes to mind.


Top
 Profile  
 
PostPosted: Thu Aug 05, 2010 1:59 pm 
Offline
Forum Newbie

Joined: Wed Jul 21, 2010 3:40 pm
Posts: 5
It's intended as a "live" development tool i guess?

the code I am storing in MySql is code for an address-list / "constituent relationship management" type application.


Top
 Profile  
 
PostPosted: Tue Aug 10, 2010 11:16 am 
Offline
Forum Newbie

Joined: Wed Jul 21, 2010 3:40 pm
Posts: 5
To clarify - one of my reasons for setting my code up this way was to have a whole set of code that is "debug" code - it gets inserted into the running code "live" when I am in "debug" mode but otherwise, it gets left out.

similarly, my code can be displayed on-screen with comments, or without comments...

or i can display all functions that are "underneath" the "foo" function (those that are called by "foo", those that are called by a function called by "foo" etc).


Top
 Profile  
 
PostPosted: Mon Aug 30, 2010 5:25 am 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
Why? You can substitute code with regular files & gool old object oriented programming. Its called the 'strategy design pattern'. And it doesn't involve adding 1,000 database queries to your page.


Top
 Profile  
 
PostPosted: Mon Aug 30, 2010 7:54 am 
Offline
DevNet Master
User avatar

Joined: Fri Jan 18, 2008 1:36 am
Posts: 3549
Location: Israel, ME
Don't you find editing code in a database considerably more cumbersome than using a text editor on text files?


Top
 Profile  
 
PostPosted: Thu Sep 02, 2010 12:13 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida


Top
 Profile  
 
PostPosted: Fri Sep 10, 2010 12:42 am 
Offline
Forum Newbie

Joined: Mon Aug 30, 2010 3:00 pm
Posts: 3


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group