2013-02-26 48 views
1

有什么办法可以在mysql中存储js文件,然后通过使用php脚本检索它并包含到网页中?从mysql存储和检索用户js文件。 php

+1

尝试询问几个较小的问题。我不想冒半小时打字来回答没有历史记录的用户。 – cja 2013-02-26 15:00:44

+0

你想要的路径js文件或整个脚本在db?解释你为什么要这样做.. – bitWorking 2013-02-26 15:01:38

+0

更好的是:[如何在MySQL中保存和检索文本数据保留换行符?](http://stackoverflow.com/questions/13738690/how-to-store-and-检索文本数据在MySQL保留行断开)PDO​​使用,最后没有'nl2br'。 – mario 2013-02-26 15:03:35

回答

2

你的HTML:

<script type="text/javascript" src="/jsserver.php?id=1"/> 

的jsserver.php脚本:

<?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; 

?> 

这应该足以为你完成这项工作。