小螞蟻學習APP接口開發(完結)—— APP錯誤日誌接口開發

APP有可能面臨的錯誤問題:php

1.    APP強退    2.    數據加載失敗    3.    APP潛在問題  等等html

錯誤日誌表,用於記錄發送過來的錯誤信息mysql

CREATE TABLE IF NOT EXISTS `error_log` (
  `id` mediumint(9) NOT NULL AUTO_INCREMENT COMMENT '主鍵',
  `app_id` tinyint(4) NOT NULL COMMENT '客戶端設備id',
  `did` varchar(50) NOT NULL COMMENT '客戶端設備信息',
  `version_id` smallint(6) NOT NULL COMMENT '版本號',
  `version_mini` smallint(6) NOT NULL COMMENT '小版本號',
  `error_log` varchar(255) NOT NULL COMMENT '錯誤信息',
  `create_time` int(11) NOT NULL COMMENT '添加時間',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='app錯誤日誌表' AUTO_INCREMENT=2 ;

當客戶端APP遇到錯誤,會發送過來相應的錯誤信息,而後插入數據庫便可,很簡單。
sql

<?php 

/**************************************
*
*    錯誤日誌寫入類
*    學php的小螞蟻
*    博客 http://my.oschina.net/woshixiaomayi/blog
*
**********************************/
//載入基礎類,進行信息判斷
//代碼內容請參考 http://my.oschina.net/woshixiaomayi/blog/519783
require_once('./common.php');

class Error extends Common{

	public function index(){
		//首先對客戶端發送的信息,進行確認
		$this->check();

		//判斷錯誤內容是否有傳來
		$error_log	=	isset($_POST['error_log'])?$_POST['error_log']:'';

		if($error_log){
			//有數據,則組裝sql語句,準備插入數據庫
			$sql="
				insert into `error_log`(
						`app_id`,
						`did`,
						`version_id`,
						`version_mini`,
						`error_log`,
						`create_time`
					)values(
						".$this->param['app_id'].",
						".$this->param['did'].",
						".$this->param['version_id'].",
						".$this->param['version_mini'].",
						'".$_POST['error_log']."',
						".time()."
					)
			";
			try{
				$connect =	Db::getInstance()->connect();
			}catch(Exception $e){
				//返回給APP的錯誤提示
				return Response::show(400,'mysql not connect');
			}
			//插入數據庫便可
			$result=mysql_query($sql,$connect);
			//根據數據庫執行結果,返回對應的數據
			if($result){
				return Response::show(200,'錯誤日誌插入成功');
			}else{
				return Response::show(400,'錯誤日誌插入失敗');
			}
		}

	}
}


$obj	=	new Error();
$obj	->	index();


 ?>

    APP開發接口的筆記今天就結束了,想起以前第一次作手機接口,確實作的簡單了,錯誤的認爲只是把數據json一下返回就ok,裏面還有這麼多學問在其中。在此感謝慕課網的singwa老師的傾情講解,使人受益不淺。將來路還很長,繼續加油     ヾ(≧▽≦*)o數據庫

相關文章
相關標籤/搜索