Home  >  Article  >  Backend Development  >  php zendframework 数据类型转换,该怎么解决

php zendframework 数据类型转换,该怎么解决

WBOY
WBOYOriginal
2016-06-13 12:57:42768browse

php zendframework 数据类型转换
 --如下
 $result = $db->fetchAll ( "select * from albums" );
这样的方式$result取出来的是Array数组的结构,访问数据的方式是$result["key"],不是类的对象

new一个类 $albums = new Albums ();这样访问数据的方式是$albums ->key

我现在要达到的效果是:

把$result的数据结构转换成$albums的数据结构

我用的是zend studio开发工具,zend framework框架,小弟刚学php,希望高手解答我的问题,在线等……

------解决方案--------------------
直接加到$db类里得了,调用时
$db->key();不是一样的吗
你再搞个Albums,还要初始化,把这个资源句柄或是结果数组导过去
你也不能写这个方法啊key()
万一还有叫key2的,方法你写不完的
写个灵活点的方法叫getAttr($column)
调用时$obj->getAttr("key2");不是更灵活

我也不会写()
------解决方案--------------------
将 数组转为 对象? settype() 
------解决方案--------------------
Zend_Db_Table 、Zend_Db_Table_Row 、Zend_Db_Table_Rowset
http://blog.csdn.net/mengxiangbaidu/article/details/7854093

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn