Having a generic data type for a database table column, is it "good" practice?
Posted
by
Yanick Rochon
on Programmers
See other posts from Programmers
or by Yanick Rochon
Published on 2012-10-11T23:42:59Z
Indexed on
2012/10/12
3:48 UTC
Read the original article
Hit count: 292
I'm working on a PHP project where some object (class member) may contain different data type. For example :
class Property {
private $_id; // (PK)
private $_ref_id; // the object reference id (FK)
private $_name; // the name of the property
private $_type; // 'string', 'int', 'float(n,m)', 'datetime', etc.
private $_data; // ...
// ..snip.. public getters/setters
}
Now, I need to perform some persistence on these objects. Some properties may be a text data type, but nothing bigger than what a varchar
may hold. Also, later on, I need to be able to perform searches and sorting.
Is it a good practice to use a single database table for this (ie. is there a non negligible performance impact)? If it's "acceptable", then what could be the data type for the data
column?
© Programmers or respective owner