警告:mysqli_close()期望参数1为mysqli,null为1

时间:2014-01-21 15:37:42

标签: php destructor

首先抱歉我的英语:)你告诉我为什么当我调用魔法__destructor()时我有这个警告,我不认为这是属性连接的范围,帮助我...谢谢大家!

<?php

class Connect{

 protected $user;
 protected $pass;
 protected $host;
 protected $db;
 protected $query;
 protected $result;
 private $connex;


 function __construct($host,$user,$pass,$database){

  $this->host=$host;
  $this->user=$user;
  $this->pass=$pass;
  $this->db=$database;



  // connesione al database

  $this->connex = new mysqli("$this->host", "$this->user", "$this->pass", "$this->db");
  if ($this->connex->connect_errno) {
   echo "Failed to connect to MySQL: (" . $this->connect_errno . ") " . $this->connect_error;
  }
  // echo 'connessione stabilita' . "\n";

 }  


function __destruct(){
 mysqli_close($this->connex);
 $this->connex = null; 
}


}



$ist = new Connect("localhost","root","","mio");
$ist->__destruct();

0 个答案:

没有答案