note 51186 deleted from ref.mysqli by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 17:23:11 +0000 |
| Subject: | note 51186 deleted from ref.mysqli by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133160@lists.php.net to get a copy of this message | ||
Note Submitter: hans at lintoo dot dk
----
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