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.