PHP是否有类似.NET的DataSet中的结构? [英] Does PHP have a construct similar to .NET's DataSet?
本文介绍了PHP是否有类似.NET的DataSet中的结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何实现一个数据集
在PHP中像.NET?
How can I implement a DataSet
in PHP like .NET?
我想这个类来读取一次从数据库中的数据,那么我应该能够使用数据,而无需重新连接到MySQL运行查询。
I want this class to read data from database only once, then I should be able to use the data without connecting again to MySQL to run queries.
select * from user
当我运行在的DataSet此查询
中的数据从内存中取出。
When I run this query on the DataSet
the data is fetched from memory.
我如何在PHP中实现这个机制?
How can I implement this mechanism in PHP?
推荐答案
您可以把你的数据到一个这样的数组:
You could push your data into an array like this:
$result = mysql_query( 'select * from user' );
$results = array();
while ( $row = mysql_fetch_array( $result ) ) {
array_push( $results, $row );
}
mysql_close();
然后你可以做任何的操作要在阵列上...
Then you can do whatever operations you want on the array...
foreach( $results as $record ){
$foo = $record['col_name'];
//...
}
这篇关于PHP是否有类似.NET的DataSet中的结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文