I am trying to pass a connected db link into a class constructor. In
the calling module, the link opens successfully and passes the
is_resource test. If I pass the same link into a class constructor,
inside the constructor it fails the is_resource test.
I am new to php. Why is the act of passing this value fundamentally
altering it? This isn't happening with variables holding text or
numeric values. Am I missing something here?
This is the class...
class HFrame {
var $index;
var $dblink;
var $dbname;
function HFrame ($i, $ln, $db) {
if (!is_resource($db)) {
die('Failed resource check in constructor: ' . mysql_error());
} else {
echo "Passed resource check in constructor<BR>\n";
}
}
This is the calling module...
include_once("hframe.php");
$server = "localhost:3306";
$username = "webuser";
$password = "notthepassword";
echo "Attempting to open database...<BR>\n";
$link = mysql_connect($server, $username, $password);
if(!$link) die ("Could not connect to database.");
if (!is_resource($link)) {
die('Failed resource check : ' . mysql_error());
} else {
echo "Passed resource check in calling
class<BR>\n";
}
echo "Attempting to create a frame...<BR>\n";
$f = new HFrame("1", "$link", "kdatabase");