<small id='Wkpzn'></small><noframes id='Wkpzn'>

    <legend id='Wkpzn'><style id='Wkpzn'><dir id='Wkpzn'><q id='Wkpzn'></q></dir></style></legend>
      1. <tfoot id='Wkpzn'></tfoot>
          <bdo id='Wkpzn'></bdo><ul id='Wkpzn'></ul>
        <i id='Wkpzn'><tr id='Wkpzn'><dt id='Wkpzn'><q id='Wkpzn'><span id='Wkpzn'><b id='Wkpzn'><form id='Wkpzn'><ins id='Wkpzn'></ins><ul id='Wkpzn'></ul><sub id='Wkpzn'></sub></form><legend id='Wkpzn'></legend><bdo id='Wkpzn'><pre id='Wkpzn'><center id='Wkpzn'></center></pre></bdo></b><th id='Wkpzn'></th></span></q></dt></tr></i><div id='Wkpzn'><tfoot id='Wkpzn'></tfoot><dl id='Wkpzn'><fieldset id='Wkpzn'></fieldset></dl></div>
      2. PDOException: 您不能序列化或反序列化 PDO 实例

        时间:2023-10-05
        <legend id='KaWNU'><style id='KaWNU'><dir id='KaWNU'><q id='KaWNU'></q></dir></style></legend>

        • <i id='KaWNU'><tr id='KaWNU'><dt id='KaWNU'><q id='KaWNU'><span id='KaWNU'><b id='KaWNU'><form id='KaWNU'><ins id='KaWNU'></ins><ul id='KaWNU'></ul><sub id='KaWNU'></sub></form><legend id='KaWNU'></legend><bdo id='KaWNU'><pre id='KaWNU'><center id='KaWNU'></center></pre></bdo></b><th id='KaWNU'></th></span></q></dt></tr></i><div id='KaWNU'><tfoot id='KaWNU'></tfoot><dl id='KaWNU'><fieldset id='KaWNU'></fieldset></dl></div>

          1. <small id='KaWNU'></small><noframes id='KaWNU'>

            <tfoot id='KaWNU'></tfoot>
              <bdo id='KaWNU'></bdo><ul id='KaWNU'></ul>

                  <tbody id='KaWNU'></tbody>
                  本文介绍了PDOException: 您不能序列化或反序列化 PDO 实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我尝试使用 memcache 在 PHP 中缓存我的 User 对象,但是在使用 PDO 时出现错误.我添加了一个 __sleep 和一个 __wakeup 函数.

                  I tried to cache my User object in PHP with memcache, but I get an error while using PDO. I added a __sleep and a __wakeup function.

                  用户.php

                  /**
                   * @var PDO
                   */
                  protected $db;
                  
                  public function __construct()
                  {
                      $this->db = getInstanceOf('db');
                  }
                  
                  public function __destruct()
                  {
                  
                  }
                  
                  public function __sleep()
                  {
                      return array('db');
                  }
                  
                  public function __wakeup()
                  {
                      $this->db = getInstanceOf('db');
                  }
                  

                  getInstanceOf('db') 返回一个 pdo 对象...

                  getInstanceOf('db') returns a pdo object...

                  返回以下错误:

                  PDOException:您不能在第 41 行的/var/www/test/User.php 中序列化或反序列化 PDO 实例

                  PDOException: You cannot serialize or unserialize PDO instances in /var/www/test/User.php on line 41

                  推荐答案

                  $this->db 很可能是一个 PDO 对象.PDO 对象无法序列化.

                  It is likely that $this->db is a PDO object. PDO objects can not be serialized.

                  __sleep() 上删除该对象并将其添加回 __wakeup()(这是您在后一种情况下已经执行的操作):

                  Remove that object on __sleep() and add it back at __wakeup() (which is what you already do in the later case):

                  public function __sleep()
                  {
                      return array();
                  }
                  

                  不能序列化的对象不能序列化.但是你试过了,所以你得到了例外.这基本上就是整个问题.只是不要告诉 PHP 序列化无法序列化的对象.

                  You can not serialize objects that can not be serialized. But you tried, so you got the exception. That's basically the whole issue. Just don't tell PHP to serialize objects that can't be serialized.

                  这篇关于PDOException: 您不能序列化或反序列化 PDO 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 PDO_DBLIB 连接到 MS SQL 数据库的 PHP 错误 下一篇:如何在 PHP 中更改 PDO/SQLite 连接的字符编码?

                  相关文章

                  最新文章

                    • <bdo id='Y5D24'></bdo><ul id='Y5D24'></ul>

                    <small id='Y5D24'></small><noframes id='Y5D24'>

                  1. <i id='Y5D24'><tr id='Y5D24'><dt id='Y5D24'><q id='Y5D24'><span id='Y5D24'><b id='Y5D24'><form id='Y5D24'><ins id='Y5D24'></ins><ul id='Y5D24'></ul><sub id='Y5D24'></sub></form><legend id='Y5D24'></legend><bdo id='Y5D24'><pre id='Y5D24'><center id='Y5D24'></center></pre></bdo></b><th id='Y5D24'></th></span></q></dt></tr></i><div id='Y5D24'><tfoot id='Y5D24'></tfoot><dl id='Y5D24'><fieldset id='Y5D24'></fieldset></dl></div>
                    <legend id='Y5D24'><style id='Y5D24'><dir id='Y5D24'><q id='Y5D24'></q></dir></style></legend>
                  2. <tfoot id='Y5D24'></tfoot>