UserDataBase
{
    public static function insert($instance)
    {
        
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
        
$statement = $pdo->prepare
        (
"
             DECLARE @return_value int
            DECLARE @UserID int
             EXEC @return_value = User_Insert
            @AccountBalance = '
".$instance->getAccountBalance()."',
            @IsAdmin = '
".$instance->getIsAdmin()."',
            @UserName = '
".$instance->getUserName()."',
            @UserID = @UserID OUTPUT
            SELECT @UserID as 'UserID'
             SELECT 'ReturnValue' = @return_value
         
");
        
$statement->execute();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
        }
        
$statement->nextRowset();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
            
$instance->setUserID($row["UserID"]);
        }
        
$statement->nextRowset();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
        }
        
unset($statement);
        
unset($pdo);
    }

    
public static function select($instance)
    {
        
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
        
$statement = $pdo->prepare
        (
"
             DECLARE @return_value int
             EXEC @return_value = User_Select
            @UserID = '
".$instance->getUserID()."'
             SELECT 'ReturnValue' = @return_value
         
");
        
$statement->execute();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
            
$instance->setAccountBalance($row["AccountBalance"]);
            
$instance->setIsAdmin($row["IsAdmin"]);
            
$instance->setUserName($row["UserName"]);
        }
        
$statement->nextRowset();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
        }
        
unset($statement);
        
unset($pdo);
    }

    
public static function update($instance)
    {
        
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
        
$statement = $pdo->prepare
        (
"
             DECLARE @return_value int
             EXEC @return_value = User_Update
             @UserID = '
".$instance->getUserID()."',
             @AccountBalance = '
".$instance->getAccountBalance()."',
             @IsAdmin = '
".$instance->getIsAdmin()."',
             @UserName = '
".$instance->getUserName()."'
             SELECT 'ReturnValue' = @return_value
         
");
        
$statement->execute();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
        }
        
$statement->nextRowset();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
        }
        
unset($statement);
        
unset($pdo);
    }

    
public static function delete($instance)
    {
        
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
        
$statement = $pdo->prepare
        (
"
             DECLARE @return_value int
             EXEC @return_value = User_Delete
             @UserID = '
".$instance->getUserID()."'
             SELECT 'ReturnValue' = @return_value
         
");
        
$statement->execute();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
        }
        
$statement->nextRowset();
        
if($row = $statement->fetch())
        {
            
if((int)$row["ReturnValue"]!=0)
            {
                
throw new Exception("Errors happened when executing the stored procedure");
            }
        }
        
unset($statement);
        
unset($pdo);
    }
}
?>
 UserBroker
{
    public static function insert($instance)
    {
        
// add business logic here
        try
        {
            UserDataBase
::insert($instance);
        }
        
catch(Exception $e)
        {
        }
    }

    
public static function select($instance)
    {
        
// add business logic here
        try
        {
            UserDataBase
::select($instance);
        }
        
catch(Exception $e)
        {
        }
    }

    
public static function update($instance)
    {
        
// add business logic here
        try
        {
            UserDataBase
::update($instance);
        }
        
catch(Exception $e)
        {
        }
    }

    
public static function delete($instance)
    {
        
// add business logic here
        try
        {
            UserDataBase
::delete($instance);
        }
        
catch(Exception $e)
        {
        }
    }
}
?>
 User
{
    private $UserID;
    
private $AccountBalance;
    
private $IsAdmin;
    
private $UserName;

    
public function getUserID()
    {
        
return $this->UserID;
    }

    
public function setUserID($UserID)
    {
        
$this->UserID = (int)$UserID;
    }

    
public function getAccountBalance()
    {
        
return $this->AccountBalance;
    }

    
public function setAccountBalance($AccountBalance)
    {
        
$this->AccountBalance = (double)$AccountBalance;
    }

    
public function getIsAdmin()
    {
        
return $this->IsAdmin;
    }

    
public function setIsAdmin($IsAdmin)
    {
        
$this->IsAdmin = (bool)$IsAdmin;
    }

    
public function getUserName()
    {
        
return $this->UserName;
    }

    
public function setUserName($UserName)
    {
        
$this->UserName = (string)$UserName;
    }
}
?>
 AppVariable
{
    public static function getDataBaseConnectionString()
    {
        
return "xxxx";//add connection string here
    }

    
public static function getODBC()
    {
        
return "odbc:Test";//add odbc connection here
    }

    
public static function getDataBaseName()
    {
        
return "Test";//add database name here
    }

    
public static function getDataBaseUserID()
    {
        
return "Joey";//add user name here
    }

    
public static function getDataBasePassword()
    {
        
return "1234";//add password here
    }
}
?>

相关文章:

  • 2022-01-12
  • 2021-11-28
  • 2021-07-15
  • 2021-09-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-10-05
  • 2021-09-28
相关资源
相似解决方案