127.0.0.1 zxt.php_get.php · zxt./angularJS - Gitee.com
error_reporting(E_ALL ^ E_NOTICE);
header("Access-Control-Allow-Orgin:*");
include 'db.class.php';
$db = new db();
/*數據庫連接語句*/
$db->mysql('localhost', 'root', '', 'angular', 'leo_', 'utf8');
//print_r($_GET);exit;
extract($_GET, EXTR_SKIP);
extract($_POST, EXTR_SKIP);
/**
* 列表
*/
if ($action == 'get_list') {
$limit = $order = '';
if (is_numeric($offset) && is_numeric($rows)) {
$limit = " LIMIT $offset,$rows";
}
$orderBy = empty($orderBy) ? 'DESC' : $orderBy;
if (is_string($orderField)) {
$order = " ORDER BY $orderField $orderBy";
}
$where = empty($where) ? '' : $db->format_condition($where);
$sql = "SELECT a.*,b.typename,b.reid FROM `leo_article` AS a INNER JOIN `leo_arctype` AS b ON a.typeid = b.id $where $order $limit";
$list = $db->query($sql)->fetchall();
// $list = $db->fetchall('article', '*', "$where", "$order", "$limit");
echo json_encode($list);
return;
}
/**
* 添加文章
* @param string $title 文章標題
* @param string $content 文章內容
* @param string $typename 所屬分類
* @return
*/
if ($action == 'add_article') {
if (empty($title)) {
$reArr['errors']['title'] = '標題必須';
}
if (empty($content)) {
$reArr['errors']['content'] = '內容必須';
}
if (empty($typeid['id'])) {
$reArr['errors']['typeid'] = '分類必須';
}
if (empty($title) || empty($content) || empty($typeid['id'])) {
echo json_encode($reArr);
return;
}
//判斷分類是否存在
$id = $db->rowcount('arctype', array('id' => "$typeid[id]"));//官
if (!$id) {
echo json_encode(array('code' => 103));
return;
}
$result = $db->insert('article', array('title' => "$title", 'content' => "$content", 'typeid' =>"$typeid[id]", 'addtime' => time()));
if ($result) {
//返回添加的數據的ID
echo json_encode(array('article_id' => $db->lastinsertid()));
return;
}
echo json_encode(array('code' => 102));
return;
}
/**
* 獲得一篇文章
*/
if ($action == 'get_article') {
$sql = "SELECT a.*,b.typename,b.reid FROM `leo_article` AS a INNER JOIN `leo_arctype` AS b ON a.typeid = b.id WHERE a.id = $id";
$data = $db->query($sql)->fetch();
// $data = $db->fetch('article', '*', array('id' => $id));
if ($data) {
echo json_encode($data);
return;
}
echo json_encode(array('code' => 102));
return;
}
/**
* 更新
*/
if ($action == 'update_article') {
if (empty($title)) {
$reArr['errors']['title'] = '標題必須';
}
if (empty($content)) {
$reArr['errors']['content'] = '內容必須';
}
if (empty($typeid)) {
$reArr['errors']['typeid'] = '分類必須';
}
if (empty($title) || empty($content) || empty($typeid)) {
echo json_encode($reArr);
return;
}
$result = $db->update('article', array('title' => "$title", 'content' => "$content", 'typeid' => "$typeid"), array('id' => $id));
$code = $result ? 101 : 102;
echo json_encode(array('code' => $code));
return;
}
/**
* 刪除
* @param string $id
* @return void
*/
if ($action == 'delete_article') {
$result = $db->delete('article', array('id' => "$id"));
$code = $result ? 101 : 102;
echo json_encode(array('code' => $code));
return;
}
/**
* 根據條件返回總頁數$sum
*/
if ($action == 'get_total') {
// $num = empty($num) || $num == 0 ? 10 : $num;
$where = empty($where) ? '' : $where;
$sum = $db->rowcount('article', $where);
// $total = ceil($sum/$num);
echo json_encode(array('total' => $sum));
return;
}
/**
* 獲取所有分類
*/
if ($action == 'get_arctype') {
$where = empty($where) ? '' : $where;
$arctype = $db->fetchall('arctype', '*',"$where");
if ($arctype) {
echo json_encode($arctype);
return;
}
echo json_encode(array('code' => 102));
return;
}
/**
* 用戶登錄
*/
//aciton=login&username=lzy&password=admin參數
if ($action == 'login') {
$reArr = array('success' => false);
//用戶名為空的情況下
if (empty($username)) {
$reArr['errors']['username'] = '用戶名必須';
}
//密碼為空的情況下
if (empty($password)) {
$reArr['errors']['password'] = '密碼必須';
}
if (empty($username) || empty($password)) {
//數組轉化為JSON格式
echo json_encode($reArr);
return;
}
$result = $db->fetch('user', 'id', array('username' => $username, 'password' => $password));
if ($result) {
echo json_encode(array('success' => true, 'message' => '操作成功'));
return;
}
echo json_encode(array('success' => false , 'message' => '用戶名密碼錯誤'));
return;
}
echo json_encode(array('status' => 'error'));
return;
一鍵復制
編輯
Web IDE
原始數據
按行查看
歷史
總結
以上是生活随笔為你收集整理的127.0.0.1 zxt.php_get.php · zxt./angularJS - Gitee.com的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 自动换行添加控件
- 下一篇: 动态规划算法php,php算法学习之动态