Skip to content

Instantly share code, notes, and snippets.

@Kathure
Last active April 18, 2018 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kathure/2ed29c1a26b7982bc93deec64efafc20 to your computer and use it in GitHub Desktop.
Save Kathure/2ed29c1a26b7982bc93deec64efafc20 to your computer and use it in GitHub Desktop.
<?php
class Driver
{
function __construct()
{
try {
$DB_host = "localhost";
$DB_user = "username";
$DB_pass = "password";
$DB_name = "ussdapp";
$this->DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
$this->DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
function checkLevel($session){
try{
$stmt=$this->DB_con->prepare("select level from session_levels where session_id =:sLevel");
$stmt->bindParam(':sLevel',$session);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC)['level'];
}catch(Exception $e){
$e->getMessage();
}
}
function insertLevel($sessionId,$phoneNumber,$level){
try{
$stmt=$this->DB_con->prepare("INSERT INTO session_levels(session_id,phoneNumber,level) VALUES(:session,:phone,:level)");
$stmt->bindParam(':session',$sessionId);
$stmt->bindParam(':phone',$phoneNumber);
$stmt->bindParam(':level',$level);
return $stmt->execute();
}catch (Exception $e){
$e->getMessage();
}
}
function updateLevel($sessionId,$newLevel){
try{
$stmt=$this->DB_con->prepare("UPDATE session_levels SET level=:level where session_id=:sessionId");
$stmt->bindParam(':sessionId',$sessionId);
$stmt->bindParam(':level',$newLevel);
return $stmt->execute();
}catch (Exception $e){
$e->getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment