dousilie9522 2011-09-07 17:51
浏览 130
已采纳

如何在MySQL数据库中存储PHP常量

I need to create a bunch of feeds in a fixed width format, they're all relatively the same in layout, but they can all have different formats.

For example:

Field 1 can be 30 bytes wide, left justified and padded with 0s
Field 2 can be 20 bytes wide, right justified padded with spaces

I'd like to store parameters for php's str_pad in the DB, but don't know the best way to store the pad_type parameter, since it's a constant, I can't read it back like:

$field = str_pad($input, $width, $pad_string, $pad_type)

I suppose I could wrap an eval() around $pad_type, but that seems sketchy.

Is there a better way to do this?

I'm stuck with, PHP 5.0, MySQL 4

  • 写回答

1条回答 默认 最新

  • dtpw54085 2011-09-07 18:05
    关注

    Use constant():

    $value = constant('NAME_OF_THE_CONSTANT_AS_STORED_IN_DB');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用