duanhuanyou6478 2017-06-12 06:10
浏览 321

如何在Mysql中处理带有嵌入变量的字符串

I am in need of some advice on how to best process code to keep things running efficiently while still returning dynamic strings to the user.

In my particular situation, I have a set of string responses that vary based on a set of six variables. Early in the project, it was easy to simply use nested if and switch statements. However, as the project advances, this set of code is becoming massive. I would very much like find a way to store this information in a database, but I am unaware of a way to do so that doesn't open up the database to vulnerabilities.

A sample script might look like the following:

printf("Let's say for a moment here, that I want to have a script that is something like this where, ". $yourname ." is printed as well as other pieces of information stored from a database such as: ".$yourfavoritefood." or ".$timesinceloggedon.".  Clearly this output will be different from person to person.");

Now imagine I have hundreds of these variable driven scripts. Is there a way to SECURELY store scripts in a mysql database so that I can query only the script I need given the program driven variables at the time?

  • 写回答

1条回答 默认 最新

  • dongzhong7299 2017-06-12 06:17
    关注

    You can store the text you create in the database or in a file and use printf with arguments to output the text, http://php.net/manual/en/function.printf.php,

    printf("Let's say for a moment here, that I want to have a script that is something like this where, :s is printed as well as other pieces of information stored from a database such as: :s or :s.  Clearly this output will be different from person to person.", [$yourname, $yourfavoritefood, $timesinceloggedon);
    

    By taking all parts that are different for different users into parameters you can find a common string which can be stored where you store translations

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题