note 69193 added to ref.mysqli
| From: | rubentrancoso at gmail dot com | Date: | Sat, 26 Aug 2006 13:01:07 +0000 |
| Subject: | note 69193 added to ref.mysqli | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116356@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 66.163.161.117
Probable Submitter: 201.47.17.220
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.mysqli.php
Edit -- https://master.php.net/note/edit/69193
Del: integrated -- https://master.php.net/note/delete/69193/integrated
Del: useless -- https://master.php.net/note/delete/69193/useless
Del: bad code -- https://master.php.net/note/delete/69193/bad+code
Del: spam -- https://master.php.net/note/delete/69193/spam
Del: non-english -- https://master.php.net/note/delete/69193/non-english
Del: in docs -- https://master.php.net/note/delete/69193/in+docs
Del: other reasons-- https://master.php.net/note/delete/69193
Reject -- https://master.php.net/note/reject/69193
Search -- https://master.php.net/manage/user-notes.php