views:

88

answers:

3

consider the following file (db-com.php):

If you wish You may skip to the question below it directly while reading it in parallel.


echo "entered db-com.php";
class DBCom {
    /**
     * @var string Holds the query string.
     * If the blank constructor is used, make sure to use the parametrized functions.
     */
    var $queryString;

    /**
     * @var resource Holds the MySQL Resource returned by mysql_query function
     */
    var $queryResult;

    /**
     * @var array Holds the entire array of the result.
     */
    var $queryArray;

    function __construct() {
        $this->queryString = $this->queryResult = $this->queryArray = '';
    }
    function __construct($qS) {
        $this->queryString = $qS;
        $this->queryResult = mysql_query($this->queryString);
        $this->queryArray = '';
    }

    /**
     *
     * @return array An array containing all the elements of the requested query.
     */
    function get_query_array() {
        if($this->queryString == '' || $this->queryString == "") {
            die("Query String is Empty. Cannot Proceed.");
        }
        for ( $i = 0 ; $fetchedArray = mysql_fetch_array( $this->queryResult ) ; $i++) {
            $this->queryArray[$i] = $fetchedArray;
        }
        return $this->queryArray;
    }
}

now when in another file i write

require ( 'some_path/db-com.php' );

the damn thing doesn't even enter this file (i.e.) even the first echo statement doesn't get displayed.

This is not happening with any other class files. Only this type of class involving sql functions. So I even started a clean blank file, tested first that control enters it or not (it did) and then wrote all of this, saved it under a different name, and included it, and again this mysterious error popped out.

Please help!

Have I gone wrong somewhere (either in my code or in my question) ? the please correct me!

A: 

Sanity check: Do you have another file on the path that's empty or otherwise outdated?

altCognito
not at allcompletely sure man!
OrangeRind
+1  A: 

Are you doing <?php ?>

Zack
yesi excluded that cause it was causing display problems in this question page
OrangeRind
+3  A: 

You have two __construct() methods. You can't overload methods like that in PHP.

You probably have display_errors turned off, so that is why you can't see the error message:

Fatal error: Cannot redeclare DBCom::__construct() in C:\test.php on line 23

Tom Haigh
lol thanks!removing the extra constructor worked!so do i use default parameters as well to achieve a pseudo overloading?
OrangeRind
you could do, or you could take an associative array as a parameter and then work out what to do based on what keys it contains.
Tom Haigh
thanks again !
OrangeRind