注意:unserialize():执行doctrine查询时,在478字节的偏移量473处出错

时间:2018-02-05 04:42:59

标签: doctrine-orm doctrine doctrine-1.2 doctrine-query

我们正在尝试执行以下的doctrine查询,并抛出unserialize():错误,偏移量为473,为578字节。

主义查询:

SELECT p FROM MyCompanyBundle:Person p 
WHERE p.dateOfExit IS NULL 
AND (p.passportCountry IS NULL OR p.passportCountry <> :india OR 
p.invitationId IS NOT NULL) 
AND (p.category <> :category_cl AND 
p.category <> :category_staff AND p.category <> :category_sev AND 
p.category <> :category_visitor)

作为上述查询的一部分,它试图获取以下数据及其抛出错误。但同样的工作是mysql查询。

Mysql表输出

a:3:{s:19:“volunteering-local0”; a:3:{s:8:“activity”; s:23:“Mystic eye kolkata 2017”; s:11:“description”; s:239:“我是在引进团队,也是在包括我在内的只有5个人组成的飞行小队中。我们被告知飞来飞去,把手伸向现场需要它的人。而且大部分都是琐碎的工作。我们的责任第一手。“; s:8:”位置“; s:7:”加尔各答“;} s:19:”志愿者 - 本地1“; a:3:{s:8:”活动“; s:17 :“内部工程”; s:11:“描述”; s:104:“我在启动日自愿参加。我有机会成为厨房工作的一部分

详细错误说明:

的Symfony \元器件\调试\异常\ ContextErrorException 在vendor / doctrine / dbal / lib / Doctrine / DBAL / Types / ArrayType.php(第58行) ArrayType-&gt; convertToPHPValue('a:3:{s:19:“volunteering-local0”; a:3:{s:8:“activity”; s:23:“Mystic eye kolkata 2017”; s:11: “描述”; s:239:“我是在引导团队,也是在包括我在内的只有5个人组成的飞行小队中。我们被告知飞来飞去,把手伸向现场需要它的人。卑微的工作是我们的第一手责任。“; s:8:”位置“; s:7:”加尔各答“;} s:19:”志愿者 - 本地1“; a:3:{s:8:”活动“ ; s:17:“内部工程”; s:11:“描述”; s:104:“我在启动日自愿参加。我有机会成为厨房工作的一部分',对象(MySQL57Platform)) 在vendor / doctrine / orm / lib / Doctrine / ORM / Internal / Hydration / AbstractHydrator.php(第316行)

请建议我解决这个学说问题的任何想法。

1 个答案:

答案 0 :(得分:0)

在你责备Doctrine ORM关于你的错误之前,让我们先检查你的序列化数组。

序列化数组(基于您的MySQL表输出):

a:3:{s:19:"volunteering-local0";a:3:{s:8:"activity";s:23:"Mystic eye kolkata 2017";s:11:"description";s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";s:8:"location";s:7:"Kolkata";}s:19:"volunteering-local1";a:3:{s:8:"activity";s:17:"Inner Engineering";s:11:"description";s:104:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too

等等,检查序列化数组有点麻烦。让它成为可读的&#34;:

a:3:{
    s:19:"volunteering-local0";
    a:3:{
        s:8:"activity";
        s:23:"Mystic eye kolkata 2017";
        s:11:"description";
        s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";
        s:8:"location";
        s:7:"Kolkata";
    }
    s:19:"volunteering-local1";
    a:3:{
        s:8:"activity";
        s:17:"Inner Engineering";
        s:11:"description";
        s:104:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too

通过使序列化数组&#34;可读&#34;,您可以在那里看到无效的序列化对象结构。

a:3:{
    s:19:"volunteering-local0";
    a:3:{
        s:8:"activity";
        s:23:"Mystic eye kolkata 2017";
        s:11:"description";
        s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";
        s:8:"location";
        s:7:"Kolkata";
    }
    s:19:"volunteering-local1";
    a:3:{
        s:8:"activity";
        s:17:"Inner Engineering";
        s:11:"description";
        s:104:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too"; // you miss the closing double quote and semicolon
    } // you miss the closing curly bracket
} // you miss the closing curly bracket

修复结构后,现在您在偏移错误方面遇到了麻烦。

  • 第1行说&#34; a:3:值&#34;。这意味着你有一个数组,里面只包含3个项目。但是价值观表明你里面只有2个项目(有键#34;志愿者 - 本地0和#34;&#34;志愿者 - 本地1&#34;)。所以第1行应该是&#34; a:2:值&#34;。

  • 第16行说&#34; s:104:value&#34;。这意味着你有一个包含104个字符的字符串。但是值表示你只有100个字符串。

  • 如果深入研究,仍有一些无效的结构。

序列化阵列已损坏,或者说“#34;无效&#34;”。这就是为什么Doctrine在尝试通过调用&#34; Doctrine \ DBAL \ Types \ ArrayType :: convertToPHPValue($ serializedValue)&#34;来尝试将给定的序列化数组反序列化为PHP数组时抛出异常的原因。即使您尝试使用PHP内部函数&#34; unserialize($ serializedValue)&#34;来反序列化它,您也会遇到错误。它会说&#34; unserialize():771字节的偏移5处的错误&#34;。

如果我必须更正它,我想象的基于序列化数组的原始PHP数组将是:

array(
    array(
        'volunteering-local0' => array(
            'activity' => 'Mystic eye kolkata 2017',
            'description' => 'I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.',
            'location' => 'Kolkata',
        ),
    ),
    array(
        'volunteering-local1' => [
            'activity' => 'Inner Engineering',
            'description' => 'I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too',
        ],
    ],
]

如果我想要那个PHP数组的序列化数组,那就是:

a:2:{
    i:0;
    a:1:{
        s:19:"volunteering-local0";
        a:3:{
            s:8:"activity";
            s:23:"Mystic eye kolkata 2017";
            s:11:"description";
            s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";
            s:8:"location";
            s:7:"Kolkata";
        }
    }
    i:1;
    a:1:{
        s:19:"volunteering-local1";
        a:2:{
            s:8:"activity";s:17:"Inner Engineering";
            s:11:"description";
            s:100:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too";
        }
    }
}

如果我想要一行序列化数组,那就是:

a:2:{i:0;a:1:{s:19:"volunteering-local0";a:3:{s:8:"activity";s:23:"Mystic eye kolkata 2017";s:11:"description";s:239:"I was in ushering team and also in the flying squad consisting of only 5 odd people including me. We were told to fly around and lend our hand to anyone who needs it in the spot. And mostly the menial jobs were our responsibility 1st hand.";s:8:"location";s:7:"Kolkata";}}i:1;a:1:{s:19:"volunteering-local1";a:2:{s:8:"activity";s:17:"Inner Engineering";s:11:"description";s:100:"I have volunteered in the initiation day . I had the oppurtunity to be part of the kitchen works too";}}}