faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 14 people (43%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How do we execute .cpp or .c file, ( stored as BLOB in db) upon reading them

Jul 10th, 2002 03:32
Saryon, Rahman Athaur,


The easiest way (if not only way) would be to put the blob into a var,
writing that var to a file, compiling the file, and then executing
the executable.
pseudocode:
<?
database_connect(server, port, username, pass);
query = "select code from table";
database_execute(query);
code = database_get_data();
fp = open_file(tempfilename.".c");
write_to_file(fp, code);
fclose(fp);
system('make tempfilename;chmod +x tempfilename');
$recv = system('tempfilename');
unlink(tempfilename);
unlink(tempfilename.".c");
database_close_connection();
?>
Have fun.