我想基于MySQL数据库中的字符串定义的类型在PHP中创建一个对象.数据库表包含以下列的列和示例数据:
id | type | propertyVal
----+------+-------------
1 | foo | lorum
2 | bar | ipsum
Run Code Online (Sandbox Code Playgroud)
...使用PHP数据类型
class ParentClass {...}
class Foo extends ParentClass {private $id, $propertyVal; ...}
class Bar extends ParentClass {private $id, $propertyVal; ...}
//...(more classes)...
Run Code Online (Sandbox Code Playgroud)
只使用一个查询,我想按id选择一行,并创建一个类型的对象,定义表的类型列,其中SELECTed行中的其他列被分配给新创建的对象.
我在考虑使用:
mysql_fetch_object()但是知道无法动态创建基于字符串的类型.怎么做到这一点?