如何将PHP代码存储在mysql表中 [英] How can I store PHP code inside of a mysql table

查看:64
本文介绍了如何将PHP代码存储在mysql表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个小的php/mysql脚本,该脚本的行为类似于wordpress博客,但对我来说只是一个小站点,仅用于存储PHP代码段.因此,我将拥有类别,然后是带有示例代码的页面,这些示例代码是使用javascript语法荧光笔编写的.与其将我的PHP代码段存储在文件中,我不希望将它们保存到mysql DB中.那么,将PHP保存到mysql中并使其脱离mysql并显示在页面上的最佳方法是什么?

I am working on building a small php/mysql script that will act something like a wordpress blog but will just be a small site for my eyes only to store PHP code snippets. So I will have categories and then pages with sample code that I write with a javascript syntax highlighter. Instead of storing my php code snippets in the file I am wanting to save them to mysql DB. So what is the best way to save PHP into mysql and to get it out of mysql to show on the page?

我的最终结果将是这样的
替代文本http://img2.pict.com/c1 /c4/69/2516419/0/800/screenshot2b193.png

My end result will be something like this
alt text http://img2.pict.com/c1/c4/69/2516419/0/800/screenshot2b193.png

更新:

我只是不确定在将其发送到mysql之前是否需要对代码做一些特殊的事情,因为它包含了所有不同种类的字符

I just wasn't sure if I needed to do something special to the code before sending it to mysql since it has all different kinds of characters in it

推荐答案

如果您不使用某种数据库抽象层,只需调用

If you're not using some kind of database abstraction layer, just call mysql_real_escape_string on the text.

这篇关于如何将PHP代码存储在mysql表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆