Basically I’m looking to create a page using PHP that will take SQL input, and output the results returned by the DB (MySQL). This is not for a production website (I understand the security implications). It’s more for learning and practice. Kind of like the SQL console section of phpMyAdmin, or even similar to what sqlzoo.net can do (I think they are using perl, but I’d like to do it in PHP). Is there a practical way to accomplish this?
For example, how can I create a page in PHP/HTML to display a table of results when I don’t know how many columns the query will return?
Also, what is the most practical way to allow a visitor to this web page to restore the DB to a default state with the original data? (e.g. create a sql dump of the original state and make a button that runs it? or is there a better way?)
Thanks!
Use
*in your SQL query to fetch all columns and loop over the results from mysql_fetch_row() or mysql_fetch_assoc() withforeach.Besides that, have you thought of using the mysql CLI ? It’s useful for those requirements.
This question should be more specific than it is now.
“create a sql dump of the original state and make a button that runs it?” – Yes. But make sure you drop/delete the existing data.