我在mac 5.5上运行的PHP 5.5.25上使用mssql。
查询
UPDATE Sessions SET
UserID = 0,
ClientIP = '127.0.0.1',
TimeStamp = 1436465436,
SessionData = 'a:1:{s:5:"forms";a:1:{s:26:"login_user_form-1436465436";O:4:"Form":15:{s:10:"*form_id";s:15:"login_user_form";s:9:"*gen_id";s:26:"login_user_form-1436465436";s:13:"*form_items";a:4:{s:8:"username";O:17:"FormItemTextField":22:{s:9:"*length";i:60;s:7:"*mask";s:0:"";s:13:"*input_type";s:6:"string";s:12:"*max_value";N;s:12:"*min_value";N;s:7:"*type";s:9:"textfield";s:7:"*name";s:8:"username";s:8:"*value";N;s:7:"*size";i:30;s:11:"*disabled";b:0;s:10:"*form_id";s:15:"login_user_form";s:8:"*print";b:1;s:8:"*label";s:8:"Username";s:14:"*placeholder";s:0:"";s:14:"*description";N;s:9:"*weight";i:0;s:9:"*parent";s:13:"primary_group";s:11:"*required";b:1;s:10:"*classes";a:0:{}s:9:"*dbname";s:8:"username";s:15:"*token_prefix";s:1:":";s:18:"*format_callback";b:0;}s:8:"password";O:16:"FormItemPassword":24:{s:13:"*min_length";i:0;s:13:"*validation";b:1;s:9:"*length";i:100;s:7:"*mask";s:0:"";s:13:"*input_type";s:6:"string";s:12:"*max_value";N;s:12:"*min_value";N;s:7:"*type";s:8:"password";s:7:"*name";s:8:"password";s:8:"*value";N;s:7:"*size";i:30;s:11:"*disabled";b:0;s:10:"*form_id";s:15:"login_user_form";s:8:"*print";b:1;s:8:"*label";s:8:"Password";s:14:"*placeholder";s:0:"";s:14:"*description";s:56:"I forgot my password.";s:9:"*weight";i:1;s:9:"*parent";s:13:"primary_group";s:11:"*required";b:1;s:10:"*classes";a:0:{}s:9:"*dbname";s:8:"password";s:15:"*token_prefix";s:1:":";s:18:"*format_callback";b:0;}s:7:"form_id";O:14:"FormItemHidden":18:{s:12:"*read_only";b:1;s:7:"*type";s:6:"hidden";s:7:"*name";s:7:"form_id";s:8:"*value";s:26:"login_user_form-1436465436";s:7:"*size";N;s:11:"*disabled";b:0;s:10:"*form_id";s:15:"login_user_form";s:8:"*print";b:1;s:8:"*label";s:6:"";s:14:"*placeholder";s:0:"";s:14:"*description";N;s:9:"*weight";i:2;s:9:"*parent";s:13:"primary_group";s:11:"*required";b:0;s:10:"*classes";a:0:{}s:9:"*dbname";s:7:"form_id";s:15:"*token_prefix";s:1:":";s:18:"*format_callback";b:0;}s:6:"submit";O:20:"FormItemButtonSubmit":18:{s:14:"*form_action";N;s:7:"*type";s:6:"submit";s:7:"*name";s:6:"submit";s:8:"*value";s:6:"Submit";s:7:"*size";N;s:11:"*disabled";b:0;s:10:"*form_id";s:15:"login_user_form";s:8:"*print";b:1;s:8:"*label";s:6:"";s:14:"*placeholder";s:0:"";s:14:"*description";N;s:9:"*weight";i:3;s:9:"*parent";s:13:"primary_group";s:11:"*required";b:0;s:10:"*classes";a:0:{}s:9:"*dbname";s:6:"submit";s:15:"*token_prefix";s:1:":";s:18:"*format_callback";b:0;}}s:9:"*action";s:14:"/demo001/login";s:9:"*method";s:4:"POST";s:8:"*title";s:0:"";s:9:"*submit";b:1;s:10:"*enctype";s:33:"application/x-www-form-urlencoded";s:13:"*title_type";s:2:"h1";s:12:"*db_values";b:0;s:10:"*gentime";i:1436465436;s:20:"*validation_errors";a:0:{}s:20:"*validate_callback";s:19:"login_user_validate";s:18:"*submit_callback";s:17:"login_user_submit";s:10:"*classes";s:0:"";}}}'
WHERE SessionID = 'krd682btg38st6r5i0om1gpbj4'
我从mssql_get_last_message()
得到的唯一警告是:
Incorrect syntax near 'a:1:{s:5:"forms";a:1:{s:26:"login_user_form-1436465436";O:4:"Form":15:{s:10:"'.
但是,如果我在SQL Server管理工作室中运行上述查询它执行正常。
显然SessionData
只是一个序列化数组。其他序列化数组使用相同的语法在系统的其他地方保存得很好。我错过了什么?
由于有几条评论要求,以下是查询的生成方式:{{3}}
答案 0 :(得分:0)
所以终于找到了问题。它们是序列化字符串中的隐藏字符。具体来说,sql server将空字符“\ 0”解释为查询字符串的终止符。我更新了我的清理函数,在单引号编码后包含这一行:
$string = str_replace("\0",'[NULL]',$string);
修正了问题。
当然,因为这是在一个字符串中出现的,我实际上需要在读取后撤消它
str_replace('[NULL]', "\0", $string);