note 69193 rejected from ref.mysqli by bjori
| From: | bjori@php.net | Date: | Sat, 26 Aug 2006 13:17:41 +0000 |
| Subject: | note 69193 rejected from ref.mysqli by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116357@lists.php.net to get a copy of this message | ||
Note Submitter: rubentrancoso at gmail dot com
----
I did a singleton db class in hope to have something like a persistent connection.
<?php
class db {
private static $singleton = null;
protected $mysql_host = "localhost";
protected $mysql_database = "default";
protected $mysql_user = "root";
protected $mysql_passwd = "";
protected $mysqli = null;
public static function getInstance() {
if( db::$singleton == null )
db::$singleton = new db();
return db::$singleton;
}
function set_connection($host,$database,$user,$passwd) {
$this->mysql_host = $host;
$this->mysql_database = $database;
$this->mysql_user = $user;
$this->mysql_passwd = $passwd;
}
function query($query) {
if(!isset($this->mysqli))
$this->mysqli = new mysqli($this->mysql_host, $this->mysql_user,
$this->mysql_passwd, $this->mysql_database);
return $this->mysqli->query($query);
}
function close() {
$this->mysqli->close();
}
}
?>
In theory, I will use it reference in other classes, and persist this referencet in session to
future use. But I don´t now why, when I try to make a query from a second class my browser hangs.