4

I'm storing CSS (stylesheets) in a MySQL database, so when I call it, I only have one way, which is to echo it in the page itself. Is there anyway I can treat the database data as a .css file basically?

7
  • if you just store the css in a text column and output it with a server side language of your choice it should work fine. Commented Oct 5, 2012 at 16:19
  • Or you could store it as binary data similarly to what is done with images, although I do not think that confers any advantages over what martincarlin87 is suggesting. Commented Oct 5, 2012 at 16:20
  • It does, for eye-candy purposes, I'm trying to refrain from loading it directly in the page, other than that, it loads perfectly. Commented Oct 5, 2012 at 16:21
  • You mean you want to eliminate the echo and mysql query statements from your code? What do you mean "eye candy" purposes. Commented Oct 5, 2012 at 16:22
  • 3
    Have you thought about having a dedicated page to pull out and display the css, and using the css header header("Content-type: text/css"); - then include that dynamic page where needed. Commented Oct 5, 2012 at 16:27

2 Answers 2

1

You will probably need to read the CSS once during start-up and save it to a file somewhere within your deploy folder, and then reference it in code with <link rel="stylesheet" type="text/css" href="style.css">. How exactly you do this will depend on your environment and specific web server.

In any case, it is always preferred to have the CSS as an external resource for a variety of reasons, e.g. because CSS resources are cached by the web browsers as opposed to dynamic pages.

Sign up to request clarification or add additional context in comments.

Comments

0

Decided to just go with loading from a .css file it's self, thanks for the help.

1 Comment

Why? What made you change your database solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.