I'm creating a codex that will store example of functions and examples on how to use functions. Can I store this information in a database? Also, is there a proper way of displaying code on a page?

  • Why not? You can store pretty much any kind of data in a database; if it makes sense to do so. – Max Vernon Sep 19 '14 at 20:26
  • HTML5 has a code element that can be used to display snippets. – George Cummins Sep 19 '14 at 20:50
  • Oracle's Apex does this very thing except with Ajax and SQL. – Vérace Sep 20 '14 at 9:14

Absolutely. In the past I have stored php and html in Postgres / MySQL / MongoDb. By doing so I was able to populate full web pages with a series of SQL queries.

| improve this answer | |

The short answer is yes.

The longer answer is yes and I would use a text data type to store the text of the code. The relevant encoding function like mysqli_real_escape_string should make sure that you do not have malformed queries when you insert the code example.

When it comes to displaying it later you could use the highlight string function to output pretty looking code that is easy on the eyes. http://php.net/manual/en/function.highlight-string.php

If you add a FULLTEXT index on the field then you could even search for entries by searching the code itself.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.