从mysql存储和检索用户js文件。php
有没有办法将js文件存储在mysql中,然后使用php脚本检索并包含到网站页面 您的html:从mysql存储和检索用户js文件。php,php,javascript,mysql,Php,Javascript,Mysql,有没有办法将js文件存储在mysql中,然后使用php脚本检索并包含到网站页面 您的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 jstabl
<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;
?>
这应该足以让你完成工作。试着问几个小问题。我不想冒险键入半小时来回答一个没有历史记录的用户。你想要js文件的路径还是db中的整个脚本?解释为什么要这样做。更好的是:对于PDO使用,只需在末尾不使用
nl2br
。