[英]Store a complex hash in Apache::Sessions:MySQL session
So, I'm trying to store a decoded JSON object into a tied apache session. 因此,我正在尝试将解码的JSON对象存储到绑定的apache会话中。 This is my code: 这是我的代码:
$url="https://apilink";
$content = get($url);
die "Can't Get $url" if (! defined $content);
$jsonOb = decode_json($content);
%aprecords = %$jsonOb;
#Push the jsonOb in the session
$session{apirecords} = \%aprecords ;
$session{apirecords}
does not store the %aprecords
reference. $session{apirecords}
不存储%aprecords
引用。 Although, when I substitute the statement to $session{apirecords} = \\%jsonOb ;
虽然,当我用$session{apirecords} = \\%jsonOb ;
代替语句时$session{apirecords} = \\%jsonOb ;
, it stores apirecords
in the sessions table but the reference to %jsonOb has no values in it. ,它将apirecords
存储在会话表中,但对%jsonOb的引用中没有任何值。
PS: I have tried the following and none of them seem to work: 1) $session{apirecords} = \\%$jsonOb ;
PS:我已经尝试了以下方法,但似乎都不起作用:1) $session{apirecords} = \\%$jsonOb ;
2) $session{apirecords} = { %aprecords } ;
2) $session{apirecords} = { %aprecords } ;
JSON object is perfectly well structured. JSON对象具有良好的结构。
Code for tying a session: 绑定会话的代码:
tie %session, "Apache::Session::MySQL", $sessionID,
{
Handle => $dbObject,
LockHandle => $dbObject,
TableName => 'sessions',
};
#If a session ID doesn't exist, create a new session and get new session ID
if (!defined ($sessionID)){
$sessionID = $session{_session_id};
$session{count}=0;
}
A helping hand would be much much appreciated! 伸出援助之手将不胜感激!
JSON Sample: https://jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943 JSON范例: https : //jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943
As pointed out by GMB. 正如GMB所指出的。 The blob size(64 KB) wasn't big enough for the JSON object. Blob大小(64 KB)不足以容纳JSON对象。 The solution is to change blob
datatype to mediumblob
. 解决方案是将blob
数据类型更改为mediumblob
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.