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 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动