Does PHP have a construct similar to .NET#39;s DataSet?(PHP 是否有类似于 .NET 的 DataSet 的构造?)
问题描述
如何在 PHP 中实现 DataSet,如 .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 的构造?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 是否有类似于 .NET 的 DataSet 的构造?
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
