class and object in php i just wanted to confirm if my codes below is correct. Feel free to make corrections.

&lt;?php
class createConnection
{
var $host="localhost";
var $username="root";
var $password="";
var $database="wilbert";
var $myconn;



function connectToDatabase()
{
$conn = mysql_connect($his-&gt;host,$this-&gt;username,$this-&gt;password);
if (!$conn)
{
    die ("Cannot connect to the database");
}

else
{
    $this-&gt;myconn = $conn;
    echo "Connection established!";
}
return $this-&gt;myconn;

}
function selectDatabase()
{
mysql_select_db($this-&gt;database);
if(mysql_error())
{

    echo "Cannot find the database ".$this-&gt;database;
}
else
{
echo "Database selected..";
}

}
function selectData()
{
mysql_select_db($this-&gt;database);

$result = mysql_query(" SELECT a.student_id, a.FirstName, b.First_Name FROM Student a        LEFT JOIN teacher b ON a.student_id = b.student_id");

echo "&lt;table border='1'&gt;
&lt;tr&gt;
&lt;th&gt;Student_ID&lt;/th&gt;
&lt;th&gt;First_Name&lt;/th&gt;
&lt;th&gt;First_Name&lt;/th&gt;
&lt;/tr&gt;";

while($row = mysql_fetch_array($result))
  {
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;" . $row['student_id']. "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['FirstName'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['First_Name'] . "&lt;/td&gt;";
  //echo "&lt;td&gt;" . $row['student_id'] . "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  }
echo "&lt;/table&gt;";
}

function closeConnection()
{
mysql_close($this-&gt;myconn);
echo "connection closed!";
}

}
?&gt;


and here is my object.

&lt;?php

include ('phpclass.php');

$connection = new createConnection(); //i created a new object

$connection-&gt;connectToDatabase(); // connected to the database

echo "&lt;br /&gt;"; // putting a html break

$connection-&gt;selectDatabase();

echo "&lt;br /&gt;";

$connection-&gt;selectData();
//$connection-&gt;closeConnection();// closed connection
?&gt;
I am a fan of loose coupling so I would suggest that you take the values of host, username, password and database out of your class. Pass the values through the constructor and set them in the constructor. This makes it easier to reuse your code.

Second, in classes such as one that creates a connection to a database I would not "echo" stuff. You better throw exceptions on error or return meaningful values to the caller.

Last, I'd suggest other names. This might be nitpicking but this has more meaning to me:

$connection = new DatabaseConnection();
$connection-&gt;open();
$connection-&gt;connectDatabase();


So, wrapped up I would have something like:

&lt;?php
class DatabaseConnection
{
    var $host;
    var $username;
    var $password;
    var $database;
    var $myconn;

    function __construct($dbhost, $user, $pass, $db)
    {
        $this-&gt;host = $dbhost;
        $this-&gt;username = $user;
        $this-&gt;password = $pass;
        $this-&gt;database = $db;
    }

    function open()
    {
        $conn = mysql_connect($his-&gt;host,$this-&gt;username,$this-&gt;password);
        if (!$conn)
            throw new Exception('Error establishing a connection.');
        else
            $this-&gt;myconn = $conn;

        return $this-&gt;myconn;
    }

    function connectDatabase()
    {
        mysql_select_db($this-&gt;database);
        if(mysql_error())
            throw new Exception("Cannot find the database " . $this-&gt;database);
    }

    function selectData($query)
    {
        mysql_select_db($this-&gt;database);
        $result = mysql_query($query);
        return $result;
    }

    function closeConnection()
    {
        mysql_close($this-&gt;myconn);
    }
}
?&gt;


Usage:

$connection = new DatabaseConnection("localhost", "root", "", "wilbert");
$connection-&gt;open();
$connection-&gt;connectDatabase();
$connection-&gt;selectData("SELECT a.student_id, a.FirstName, b.First_Name FROM Student a LEFT JOIN teacher b ON a.student_id = b.student_id");


See how the other names make more sense? Try to avoid verbs as a classname. Methods can and most likely will be or contain verbs, but not classnames. Also, leaving the query out of the class leaves you the option to use the same code for other queries. 

Note that this is no perfect code, I was only suggesting what might be changed. Hope this helps! :)

Edit:

You call the function selectData() and pass the query-string as a parameter. This changes nothing, it gives the same result as your code. Only in my case you can pass other queries to the function whereas your function is limited to the embedded query.

Now for the result. This has also to do with the decoupling of your connection-class and what will be shown to the user. I showed u the usage of the class, the code below is how you can process the result. Create a function (but not in the connection class!) that returns the result in a table:

function resultTable($sqlResult)
{
    $table = "&lt;table border='1'&gt;";
    $table .= "&lt;tr&gt;&lt;th&gt;Student_ID&lt;/th&gt;&lt;th&gt;First_Name&lt;/th&gt;&lt;th&gt;First_Name&lt;/th&gt;&lt;/tr&gt;";

    while($row = mysql_fetch_array($sqlResult))
    {
        $table .= "&lt;tr&gt;&lt;td&gt;" . $row['student_id']. "&lt;/td&gt;";
        $table .= "&lt;td&gt;" . $row['FirstName'] . "&lt;/td&gt;";
        $table .= "&lt;td&gt;" . $row['First_Name'] . "&lt;/td&gt;&lt;/tr&gt;";
    }
    $table .= "&lt;/table&gt;";

    return $table;
}


And the usage:

$connection = new DatabaseConnection("localhost", "root", "", "wilbert");
$connection-&gt;open();
$connection-&gt;connectDatabase();
$result = $connection-&gt;selectData("SELECT a.student_id, a.FirstName, b.First_Name FROM Student a LEFT JOIN teacher b ON a.student_id = b.student_id");
echo resultTable($result);


You could create a new class in which you define all sorts of methods like these to process a result and return it to the view-file where you will show it on the screen. Hope this clarifies it. :)