View Single Post
Old 11-14-2007, 05:28 PM   #2 (permalink)
Karl
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

You're getting the error because you're trying to access a property of the class ($this->conneciton) even though it has not yet been set.

Firstly, you should declare your $connection property as a member of the class:

Code:
class mysql { 
    private $connection;
    ...
You then need to store the connection in the constructor when you first connect to the database, amend the code like this:

Code:
  function Connect($host, $name, $pass, $db){

  $this->connection = mysql_connect("$host",
  "$name",
  "$pass");
  mysql_select_db("$db", $this->connection);

  }
It's only a small change, basically we're just storing the connection as a property of the class now, so we can use it in other methods/functions of the class. Making these changes should sort that error out.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote