Is there any way to store a js file in mysql and then by using a php script retrieve it and include to website page?
Asked
Active
Viewed 216 times
1
-
1Try asking a few smaller questions. I don't want to risk typing for half an hour to answer a user with no history. – cja Feb 26 '13 at 15:00
-
you want the path to the js file or the whole script in db? explain why you want to do this.. – bitWorking Feb 26 '13 at 15:01
-
Better yet: [How to store and retrieve text data in MySQL preserving the line breaks?](http://stackoverflow.com/questions/13738690/how-to-store-and-retrieve-text-data-in-mysql-preserving-the-line-breaks) for PDO usage, just without the `nl2br` at the end. – mario Feb 26 '13 at 15:03
1 Answers
2
Your html:
<script type="text/javascript" src="/jsserver.php?id=1"/>
The jsserver.php script:
<?php
// connect to your db the way you like
$id=intval($_REQUEST['id']);
$query='SELECT jsscript FROM jstable WHERE id='.$id;
// execute query
// fetch javascript code from table "jstable" field "jsscript"
// $jsscript contains the javascript code
header('Content-type: text/javascript');
echo $jsscript;
?>
This should be enough for you the get the job done.

Ghigo
- 2,312
- 1
- 18
- 19