dongya1228 2009-02-28 15:14
浏览 19
已采纳

在php中如何做会话实例?

I'm quite new on php and am trying to learn it.

My question is rather simple but I've been a bit lost while googling for it.

I just want to create an object to manage the database connection. I already did the object and now the problem I'm facing is:

How do i keep it instanced to a session? (So that i don't need to open/close the connection to the database on every page load) And how do I call it afterward?

Are there any way to declare a destroyer, so that when the instance is dying, the connection to the database gets closed?

  • 写回答

2条回答 默认 最新

  • dongquming3255 2009-02-28 15:24
    关注

    If you define a __destruct() method on your object, it'll get called when the object is about to be destroyed. You can use this to close your database connection.

    You can also use __sleep() and __wakeup() for serializing your objects. They'll get called automatically upon serialization and unserialization. You could use these methods to connect and disconnect as required.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答