note 51186 added to ref.mysqli
| From: | hans at lintoo dot dk | Date: | Wed, 23 Mar 2005 04:33:53 +0000 |
| Subject: | note 51186 added to ref.mysqli | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86821@lists.php.net to get a copy of this message | ||
While writing a class that extends mysqli I ran across some rather strange bugs,
that however did resove itself, when I found out that they were caused by:
<?php
parent::__construct( ... ... ... $this->dbase_password);
?>
so I changed it to the following:
<?php
/**
* Database class for handling database connections.
*
* @author Hans Duedal
* @version 22 Marts 2005
*/
class DBase extends mysqli {
protected $dbase_hostname;
protected $dbase_username;
protected $dbase_password;
protected $dbase_name;
/**
* Consctructor for objects of class DBase
*
* @param File $settings_ini_file
*/
public function __construct(File $settings_ini_file) {
$ini_array = parse_ini_file($settings_ini_file->requireFilePath());
$this->dbase_hostname = $ini_array["dbase_hostname"];
$this->dbase_username = $ini_array["dbase_username"];
$this->dbase_password = $ini_array["dbase_password"];
$this->dbase_name = $ini_array["dbase_name"];
parent::__construct(
$ini_array["dbase_hostname"],
$ini_array["dbase_username"],
$ini_array["dbase_password"],
$ini_array["dbase_name"]);
if (mysqli_connect_error()) {
throw new Exception("Connect exception:\n".mysqli_connect_error());
}
}
/**
* Desctructor for objects of class DBase, closes the connection
*
*/
public function __destruct() {
parent::__destruct();
parent::close($this);
}
/**
* Accessor method to return protected variable $dbase_name
*
* @return string
*/
public function getName() {
return $this->dbase_name;
}
/**
* Raw MySQL query
* throws exception
*
* @param string $query
* @return mysqli_result
*/
public function query($query) {
$result = parent::query($query);
if (mysqli_error($this))
throw new Exception("Query exception:\n".mysqli_error($this));
return $result;
}
}
?>
btw the File class is my own as well... couldn't find any File object in PHP5 ? :S
They are both avaible for download at:
http://www.lintoo.dk/public/dbase_and_file_class.zip
Hans Duedal // hans@lintoo.dk
----
Manual Page -- http://www.php.net/manual/en/ref.mysqli.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51186
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51186&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51186&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51186&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51186&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51186&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51186&report=yes
Search -- http://master.php.net/manage/user-notes.php