I’m calling a class that does not seem to be executing any of its methods. Consider the following file (db-com.php):
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;
}
}
When in another file I write:
require ( 'some_path/db-com.php' );
it 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.
Where have I gone wrong?
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: