首页 > 代码库 > php中的捕获异常操作

php中的捕获异常操作

<?php
if(!isset($_SESSION)){
    session_start();
}
include ‘../common/mysql.class.php‘;
include ‘../common/common_notice.php‘;
try{
    $arr=[];
    $config=[];
    $pdo=new Mysql($config);
    $game_id=(int)(trim($_POST[‘game_id‘]));
    $game_type=(int)$_POST[‘game_type‘];
    $uid=S_SESSION[‘uid‘];
    if(!$game_type){
        throw new Exception(NOTICE_NUM_41,0);
    }

    if(!$game_id){
        throw new Exception(NOTICE_NUM_37,0);
    }

    if(!$uid){
        throw new Exception(NOTICE_NUM_40,0);
    }
    $collection_time=time();//游戏的收藏时间

    $sql="INSERT INTO `ks_game_collection`(`game_id`,`collection_time`,`game_type`,`uid`) VALUES(‘$game_id‘, ‘$collection_time‘,‘$game_type‘,‘$uid‘)";
    $rs=$pdo->doSql($sql);

    if($rs>0){
        $arr=[‘status‘=>1,‘notice_content‘=>NOTICE_NUM_38];
        exit(json_encode($arr,true));
    }else{
        throw new Exception(NOTICE_NUM_39,0);
    }
}catch(Exception $e){
    $arr=[‘status‘=>$e->getCode(),‘notice_content‘=>$e->getMessage()];
    exit(json_encode($arr,true));
}

 

php中的捕获异常操作