dongyan8896 2014-02-10 11:38
浏览 89


I have extended my Database Models from the mysqli class, but i don't want it to reconnect everytime i instantiate a new model, because it really slows down the whole script.

I have a Database class extends from mysqli, and other model classes extending from Database.

My Database class looks like this :

class Database extends mysqli {

    // some properties ...

    public function __construct() {
        parent::__construct(MySQL_HOST, MySQL_USER, MySQL_PASS, MySQL_DATABASE);

        // initializing stuff ..             

    // some other methods...     

A sample model class would look like this :

class User extends Database {
    protected $table = "users";

public function __construct($id = null) {
    // Calling the parent constructor.
    if($id) {
        // This is the current logged-in user.
        // Importing all session data into this object.
        // ^^ This imports all the user related session data into this object 
        // i don't think it's relevant but i'll leave it here just in case.

My question is,

  • How can i check if there is an active mysqli connection?

  • How can i prevent it from reconnecting and use the active connection instead?

  • What other approaches can i follow?

  • Should i migrate to PDO, do i have to? Why?

P.S.: Migrating to PDO will be a lot of rework, as i've already built things over mysqli.

  • 写回答

3条回答 默认 最新


      相关推荐 更多相似问题


      • ¥30 VB6.0操作 webview2内核的浏览器如何精确实现网页弹窗处置
      • ¥15 pr导出的视频打不开,提示“缺少编解码器”怎么解决
      • ¥15 html里js获取php参数值不成功,帮改代码
      • ¥20 如何控制ant design的InputNumber组件 最多输入5位小数
      • ¥15 c语言学生基本信息管理系统
      • ¥100 火车头采集器采集求解
      • ¥88 关于#运行时间 时间重叠 和非重叠#的问题,如何解决?
      • ¥15 C语言,密切接触者追踪
      • ¥20 关于计算机网络问题,请附带讲解
      • ¥30 自动识别图像目标并判断