Created
January 14, 2016 17:18
-
-
Save hungdh0x5e/6f04d2e4b205d440ac1d to your computer and use it in GitHub Desktop.
GCM with Android Tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DB_Functions { | |
private $db; | |
//put your code here | |
// constructor | |
function __construct() { | |
include_once './db_connect.php'; | |
// connecting to database | |
$this->db = new DB_Connect(); | |
$this->db->connect(); | |
} | |
// destructor | |
function __destruct() { | |
} | |
/** | |
* Storing new user | |
* returns user details | |
*/ | |
public function storeUser($name, $email, $gcm_regid) { | |
// insert user into database | |
$result = mysql_query("INSERT INTO gcm_users(name, email, gcm_regid, created_at) VALUES('$name', '$email', '$gcm_regid', NOW())"); | |
// check for successful store | |
if ($result) { | |
// get user details | |
$id = mysql_insert_id(); // last inserted id | |
$result = mysql_query("SELECT * FROM gcm_users WHERE id = $id") or die(mysql_error()); | |
// return user details | |
if (mysql_num_rows($result) > 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return false; | |
} | |
} | |
/** | |
* Get user by email and password | |
*/ | |
public function getUserByEmail($email) { | |
$result = mysql_query("SELECT * FROM gcm_users WHERE email = '$email' LIMIT 1"); | |
return $result; | |
} | |
/** | |
* Getting all users | |
*/ | |
public function getAllUsers() { | |
$result = mysql_query("select * FROM gcm_users"); | |
return $result; | |
} | |
/* | |
* Delete user from regId? | |
*/ | |
public function removeUserByRegId($registration_ids){ | |
$query = "DELETE FROM gcm_users WHERE "; | |
$query.=" gcm_regid='".implode("' or gcm_regid = '", $registration_ids)."'"; | |
$result = mysql_query($query); | |
$no_of_rows = mysql_num_rows($result); | |
if ($no_of_rows > 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
/** | |
* Check user is existed or not | |
*/ | |
public function isUserExisted($email) { | |
$result = mysql_query("SELECT email from gcm_users WHERE email = '$email'"); | |
$no_of_rows = mysql_num_rows($result); | |
if ($no_of_rows > 0) { | |
// user existed | |
return true; | |
} else { | |
// user not existed | |
return false; | |
} | |
} | |
/* | |
* Check registration is existed or not | |
*/ | |
public function isTokenExisted($gcm_regid){ | |
$result = mysql_query("SELECT email from gcm_users WHERE gcm_regid = '$gcm_regid'"); | |
$no_of_rows = mysql_num_rows($result); | |
if ($no_of_rows > 0) { | |
// user existed | |
return true; | |
} else { | |
// user not existed | |
return false; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment