Freid001 Posted February 11, 2012 Share Posted February 11, 2012 Hi! I was wondering if there is a way to execute php code which is stored in mysql database using php. At the minute I am using a echo to try and run php code stored in a mysql database but this just displays the code and does not run the php code. Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/256899-is-a-way-to-execute-php-code-which-is-stored-in-mysql-database/ Share on other sites More sharing options...
Ivan Ivković Posted February 11, 2012 Share Posted February 11, 2012 Try something like this: $string = $fetch['code']; // contains: echo "String"; eval($string); Quote Link to comment https://forums.phpfreaks.com/topic/256899-is-a-way-to-execute-php-code-which-is-stored-in-mysql-database/#findComment-1317009 Share on other sites More sharing options...
scootstah Posted February 11, 2012 Share Posted February 11, 2012 You could use eval(), but that is generally frowned upon and there is probably a better way to do what you want. Why, may I ask, do you want to do this? Quote Link to comment https://forums.phpfreaks.com/topic/256899-is-a-way-to-execute-php-code-which-is-stored-in-mysql-database/#findComment-1317056 Share on other sites More sharing options...
Freid001 Posted February 11, 2012 Author Share Posted February 11, 2012 I am creating a PHP textbased RPG. For the RPG I am creating missions which will be played by users. Each of the mission details and data will be stored in a MYSQL database. My problem is that each mission contains separate parts to it and will thus require different php code to run. I could hard code the data into the PHP code but that would take ages and would be hard to run and edit. Quote Link to comment https://forums.phpfreaks.com/topic/256899-is-a-way-to-execute-php-code-which-is-stored-in-mysql-database/#findComment-1317063 Share on other sites More sharing options...
scootstah Posted February 11, 2012 Share Posted February 11, 2012 Why would it be any easier or faster to save it to a database verses save it to a file? It seems that a database connection, selecting the row, and eval()'ing it is a lot more work than simply including a file. Quote Link to comment https://forums.phpfreaks.com/topic/256899-is-a-way-to-execute-php-code-which-is-stored-in-mysql-database/#findComment-1317064 Share on other sites More sharing options...
Freid001 Posted February 11, 2012 Author Share Posted February 11, 2012 I am storing the data in MYSQL because it needs to cross reference data with other tables in the data base. Quote Link to comment https://forums.phpfreaks.com/topic/256899-is-a-way-to-execute-php-code-which-is-stored-in-mysql-database/#findComment-1317068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.