Parris Varney
Parris Varney

Reputation: 11478

How to store PHP constants in a MySQL db

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

Upvotes: 0

Views: 788

Answers (1)

feeela
feeela

Reputation: 29932

Use constant():

$value = constant('NAME_OF_THE_CONSTANT_AS_STORED_IN_DB');

Upvotes: 2

Related Questions