I am trying to move from procedural to oop programming and having a few problems!!
Firstly I have a include with all my database connection details:
//setup connection information and place into variables for reuse later.
$db_address = "XXXXXXXX";
$db_username = "XXXXXXXXXXXX";
$db_passsword = "XXXXXXXXXXX";
$db_name = "XXXXXXXXXX";
//test the database connection.
$db_connection = @mysql_connect($db_address,$db_username,$db_passsword) or die("Couldn't Connect.");
//test there is a database.
$db_select = @mysql_select_db($db_name,$db_connection) or die("Couldn't select database.");
Then I have a file where i am trying to write a class to extract info from my table:
include ("dbconnector.php");
class db_control
{
var $dbconnection;
var $table; //table that we will select from
var $sql; //query
var $row;
var $result;
function selectInfo ()
{
$this->dbconnection = $db_connection;
$this->sql = "SELECT * " .
"FROM ".$this->table." ";
$this->result = mysql_query($this->sql,$this->dbconnection)
or die('Could not get connect to database; ' . mysql_error());
$this->row = mysql_fetch_array($this->result);
}
}
Then I try to call the class:
$contact_details = new db_control();
$contact_details->table = 'contact_details';
$email = $contact_details->row['contact_email'];
echo "<p>$email</p>";
I have no idea where im going wrong :queasy: