Hi, I'm reading the Zend PHP tutorial (http://www.zend.com/php/beginners/php101-7.php) and I came across the constructor, public function _construct(). PHP5 is enabled on my server. However, I've discovered that I had to actually call the constructor. Isn't the constructor supposed to run on its own when we create a new class?
For example:
... bunch of code...PHP Code:include_once("db_settings.php");
class dbFunctions extends dbSettings {
// properties
public $db;
public $connector;
public $result;
// constructor
public function _construct() {
parent::_construct();
$this->connector = mysql_connect($this->db_host,$this->db_user,$this->db_pass);
if(!$this->connector) {
die ("Could not connect to MySQL.");
}
$this->db = mysql_select_db($this->db_name,$this->connector);
if(!$this->db) {
die ("Could not select the database.");
}
print "success!";
}
and in install.php
and that displays...PHP Code:include_once("db_functions.php");
$connect = new dbFunctions();
$connect->_construct();
success!
However, if I remove $connect->_construct();, everything falls apart. My solution was to change public function _construct() to public function dbFunctions(). This is not what I want to do. How can I get _construct() to work on its own like it's supposed to? Thanks for any help.




Reply With Quote