Jump to content

Getting no errors, but the query isn't pulling the data


Clandestinex337

Recommended Posts

So my other functions work, where I create new user and update user, but showing the users doesn't seem to work

 

class MySql
{
	var $host;
	var  $user;
	var  $password;
	var  $database;
	public  $db_handle;

	public function connect($db_host, $db_user, $db_password, $db_database)
	{
		$this->host = $db_host;
		$this->user = $db_user;
		$this->password = $db_password;
		$this->database = $db_database; 

		$this->db_handle = mysql_connect($this->host, $this->user, $this->password)or die('could not connect to db');
		mysql_select_db($this->database)or die('could not select db');
	}

	public function query($sql)
	{
		return mysql_query($sql, $this->db_handle) or die (mysql_error());
	}

	public function fetch($sql)
	{
		return mysql_fetch_assoc($this->query($sql), $this->db_handle);
	}
}

class User 
{
	public $db;
	public $id;
	public $username;
	public $password;

	public function __construct(MySql $db, $id = '0')
	{
		$this->db = $db;
		$this->id = $id;

		if($this->$id !== 0)
		{
			$result = $this->db->query("SELECT `username`, `password` FROM `user` WHERE `id` ='{$this->id}'");

				if($result)
				{
					$this->username = $result->username;
					$this->password = $result->password;
				}
		}
	}

$user = new User($connect, 31);
echo $user->getUsername();

 

I can't seem to spot why its not working

 

This is my print_r

User Object ( [db] => MySql Object ( [host] => localhost [user] => root [password] => [database] => imgnexus [db_handle] => Resource id #4 ) [id] => 31 [username] => [password] => )

 

let me know if you need the full code..

 

Cheers

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.