Hi all
I have been using Procedural PHP for quite some time now and decided to take the plunge into using Classes for the re-usability factor and typing
"SELECT * FROM `table`"
in every page gets rather tiresome. lol
So i figured i would try to create a class to perform the following things.
1: Connect to a database
2: Find the db
3: Run a query ( got tired of typing "mysql_query" in every page)
4: Display a query
The following class i have at the moment but as im real new to Classes i was wondering if someone could either
A: Point me to a good tutorial for achieving these things.
B: Help me solve this problem with some little explanations as to why im receiving a T_FUNCTION error message.
The Code
<?php
///Make a connection to the database.
class Connection{
///Declare connection variables.
var $host = "localhost";
var $username = "root";
var $password = "";
var $database = "ClassTest";
function ConnectToServer(){
$connect = mysql_connect($this->$host,$this->$username,$this->$password);
if (!$connect){
echo "Unable to connect to Host!";
}else{
echo "Connection Established";
///Connection established now find the db.
//ConnectToDatabase();
}
}
function ConnectToDatabase(){
$selectdb = mysql_select_db($this->$database,$this->$connect);
if(!selectdb){
echo "<li>Could not find database!</li>";
}else{
echo "<li>DB FOUND!</li>";
}
}
}
?>
This is what i have in my index.php
<?php
include_once('ConnectionClass.php');
$connection = new Connection();
?>
Many Thanks Shab