Can't pass mysqli connection in session in php

前端 未结 3 1109
余生分开走
余生分开走 2020-11-30 13:56

I\'m trying to pass a session with mysqli connection for multiple queries on the site, but when I try to do a query it outputs a warning \"Couldn\'t fetch mysqli\"



        
3条回答
  •  半阙折子戏
    2020-11-30 14:30

    Yes, it is explicitly impossible.

    See PHP Documentation here mentioning in a highlighted Warning: "Some types of data can not be serialized thus stored in sessions. It includes resource variables or objects with circular references (i.e. objects which passes a reference to itself to another object)."

    MySQL connections are one such kind of resource.

    You have to reconnect on each page run.

    This is not as bad as it sounds if you can rely on connection pooling via mysql_pconnect(), but first see more background info on mysql_pconnect() in this article.

提交回复
热议问题