复制php资源 [英] duplicating php resources

查看:194
本文介绍了复制php资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以复制函数产生的资源,例如mysql_query?



它可能听起来很蠢,但我想重用这些资源,重新键入mysql_query()再次只是为了使用有一个resource..like例如

  $ rsrc = mysql_query * FROM`table` LIMIT 0,1'); 
$ rows = mysql_fetch_array($ rsrc);
print_r($ rows);

当你获取一个资源,它的价值会消失(这是我想)
我想要做的是再次使用again.i甚至尝试..

  $ rsrc = mysql_query `LIMIT 0,1'); 
$ rsrc_copy = $ rsrc;


解决方案


资源,它的价值会消失(这是我想)我想做的是再次使用again.i甚至尝试..


您遇到的不是价值消失,而是结果的内部数据指针向前移动一行。 / p>

理论上可以使用 mysql_data_seek() ,但这样做很少实用。我从来没有见过这个在现实世界的应用程序中使用。而是重复使用您提取的结果,例如通过将行存储在数组中。


are there any way to duplicate the resources produced by functions such as mysql_query?

it may sound dumb but i wanted to reuse such resources so that i won't retype the mysql_query() again and again just to use have a resource..like for example

$rsrc = mysql_query('SELECT * FROM `table` LIMIT 0,1');
$rows = mysql_fetch_array($rsrc);
print_r($rows);

when you fetch a resource, it's value will disappear (that's what i think) what i wanted to do is to reUse it again.i even tried..

$rsrc = mysql_query('SELECT * FROM `table` LIMIT 0,1');
$rsrc_copy = $rsrc;

解决方案

when you fetch a resource, it's value will disappear (that's what i think) what i wanted to do is to reUse it again.i even tried..

What you are experiencing is not the value disappearing, but the result's internal data pointer moving one row ahead.

It is theoretically possible to move the internal data pointer around using mysql_data_seek(), but it is rarely practical to do so. I've never seen this used in a real world application. Rather re-use the result you fetched, e.g. by storing the rows in an array.

这篇关于复制php资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆