Re: storing functions in a database

From: Date: Mon, 26 Jun 2000 21:03:08 +0000
Subject: Re: storing functions in a database
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-638@lists.php.net to get a copy of this message
"Kris Mach" <no@spam.com> wrote in message news:3957AE3A.602DFE24@spam.com... > Datahntr wrote: > > > > I would like to store my functions in a database instead of a include > > > file, is that possible? > > > > Yes. Why, who knows. But yes. > > How would I go about doing this? Using the eval? Dumping it to a temporary file > and include it like you mentioned below? > > I do have a reason to store the functions in a database instead of a file. I assume you know how to send queries to your Oracle database server, because I don't. So, issue a select that would result in the appropriate row being returned. If you had, say ... ID,DESC,CODE where ID is a number, DESC is a string, and CODE (where you store your functions) is a BLOB, you'd SELECT so that you get the row of data that you want. Then, write CODE to a file (PHP has a tempnam function which gives random names to be used for temporary files - see http://www.php.net/manual/function.tempnam.php3) using the fopen and fputs functions (remembering to fclose after you are done writing to the file). Finally, assign the name of the file you just created to some variable, and include($filename); See http://www.php.net/manual/function.eval.php for how the eval function works. > > > > Also if I were to store some php code in a database field, could I > > > retrieve it and have it parsed through php and then spit out to the user > > > instead of just having it spit out directly from the database to the > > > user? > > > > Look at "eval". I don't know how well suited it is to being used with large > > chunks of code, however. You could just dump it to a temporary file and > > include it, then delete the file afterward. > > Would this be a ok thing to do? Or do you think that the server performance > would be impacted greatly? I wouldn't do it, but I also cannot conceive of any possible reason to store php functions in a database. You may have a good reason, but it can probably done with only a slight bit more complexity (or maybe a whole lot less, depending on how much you like Oracle) without using a database at all. I think performance could be affected too, depending on how you plan to use this functionality. -- O.

« previous php.db (#638) next »