Dear All
I need your help. Im facing strange problem. I have a simple test class and a function to connect to mysql. When i create the object and call the function it says it cannot as the variables are null. Below is the code of my class. and below the class is the code of my object .
reg.php
class registration{
var $servername="localhost";
var $username="root";
var $password="";
var $dbname="dummy";
var $conn;
function connectDB(){
//connect to the db
$conn = mysql_connect($servername,$username,$password);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}else {
return "connected";
}
}
}
?>
testpage.php
<?php
require_once('reg.php');
$regdata = new reg();
echo("name = ".$regdata->connectDB());
?>
Now, please gurus, tell me why i cannot connect. I always get the error that variables are empty.
Even if i try to print the class variables it says empty.....but y is it empty. i have explicitly declared it.
Plz help.