RSS

PHP User Class

18 Mar
<?php
class User
{
private $user_id;
private $username;
private $password;
private $email;
protected static $table_name="lbs_user";

public function __construct($username="",$password="",$email="")
{
$this->username = $username;
$this->password = $password;
$this->email    = $email;
}

/* Add a new user.
* Returns true on success, false on error */

public function getUserId()
{
return  $this->user_id;
}

public function create()
{
global $gdbObj;
$username = $gdbObj->escape_value($this->username);
$password = $gdbObj->escape_value($this->password);
$email    = $gdbObj->escape_value($this->email);

$sql = "INSERT INTO ".self::$table_name." (username,password,email) values('$username','$password','$email')";
if($gdbObj->query($sql))
{
$this->user_id = $gdbObj->insert_id();
return true;
}
else
{
return false;
}

}

/* Update user profile.
* Returns true on success, false on error */
public function update()
{

}

/* Remove an user.
* Returns true on success, false on error */
public function delete()
{

}

}
$guserObj = new User();
?>


Advertisements
 
1 Comment

Posted by on March 18, 2012 in OOP, PHP

 

Tags:

One response to “PHP User Class

  1. maxanda

    May 29, 2012 at 1:14 am

    Great class. I can see it’s easy to add other fields to it as well. However, I noticed the update and delete functions have nothing contained within. Is that done on purpose?

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: