Results 1 to 11 of 11

Thread: [RESOLVED] Help with PHP5 constructor

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    14

    Resolved [RESOLVED] Help with PHP5 constructor

    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:
    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!";

    ... bunch of code...

    and in install.php

    PHP Code:
    include_once("db_functions.php");
    $connect = new dbFunctions();
    $connect->_construct(); 
    and that displays...

    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.
    Last edited by selfishy_me; May 11th, 2006 at 02:32 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width