Read the array in the session-php Tutorial

Source: Internet
Author: User
Read the array problem in the session. this post is Last edited by $ query & nbsp; select & nbsp; * & nbsp; from & nbsp; at 2013-12-2616: 50: 24; ##__ arctype & nbsp; where & nbsp; isbaike1; & nbsp; & read the array in the session

This post was last edited by zl2727 at 16:50:24 on

$query ="select * from #@__arctype where isbaike=1";
$this->dsql->Execute("bkarry",$query);
$bkarry=array();
session_start();
if(!session_is_registered("bkarry")){

while($row2 = $this->dsql->GetArray("bkarry"))
{
$bkarry[]=$row2;
}
$bkarry2=serialize($bkarry);
$_SESSION['bkarry']=$bkarry2;


}else{

$bkarry=unserialize($_SESSION['bkarry']);
}
//unset($_SESSION['bkarry']);
//var_dump($bkarry);

while($row = $bkarry)
{var_dump($row);

}
exit();

When the array is retrieved from the session, the system will not be able to cyclically report insufficient memory.
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1176 bytes)

Could you help me to see if there is any problem or make it easier to write?

I want to query more than 3000 pieces of data. it is too slow to query each query. so I want to save the data to the session and do not need to query it every time.

Share: More


------ Solution --------------------
The problem is not stored in the session, but is processed after reading!
This is an endless loop
while($row = $bkarry) {
var_dump($row);
}

But this will not cause insufficient memory. you should point out the location where there is insufficient memory.


session_start();
$query ="select * from #@__arctype where isbaike=1";
if(! isset($_SESSION['bkarry'])) {
$this->dsql->Execute("bkarry",$query);
while($row2 = $this->dsql->GetArray("bkarry"))
{
$_SESSION['bkarry'][] = $row2;
}
}
$bkarry =& $_SESSION['bkarry'];

The session itself is serialized without the need to serialize itself. The serialized session strings are much shorter than serialize strings.
Make $ bkarry a reference of $ _ SESSION ['bkarry'], and reduce the memory by half.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.