コード例 #1
0
ファイル: NewsCD.php プロジェクト: geminas/future
<?php

//20151016, V3 modified-FFW (API)
//*Initialization, Configuration, and Definition
require_once $_SERVER['DOCUMENT_ROOT'] . "/../app_config/FutureForumWWW.php";
//Include Modules
require_once 'general.php';
//Input argument processing
$argin = processRequestArguments();
//Now do stuff
//When encounter errors, use stopBecause("", optional ERROR_NUMBER default -1);
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
if (!isset($_SESSION['user_id'])) {
    stopBecause("登录信息有误!", 1);
}
if (isset($argin['remove'])) {
    queryDB("DELETE FROM `news` WHERE id='{$argin['remove']}'");
}
if (isset($argin['create'])) {
    queryDB("INSERT INTO `news` (`code`, `publishTime`,`title` )\r\n    VALUES ('{$argin['create']}', NOW(), '新建新闻  ')");
}
//*JSON encoding and return
//defaults: 'status'=0, 'data'=array(), 'message'='', 'redirection'='';
produceOutputV3(array());
コード例 #2
0
ファイル: general.php プロジェクト: geminas/future
function accessDB($q)
{
    // Make the connection:
    $dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_NAME, $dbc);
    $result = array();
    // If no connection could be made, trigger an error:
    if (!$dbc) {
        stopBecause('Could not connect to MySQL: ' . mysql_error(), 201);
    } else {
        // Otherwise, set the encoding:
        mysql_set_charset('utf8', $dbc);
    }
    // Make query
    $result['query'] = mysql_query($q, $dbc);
    $result['insert_id'] = mysql_insert_id($dbc);
    // Check and return
    if ($result['query'] === false) {
        $q = str_replace("\r\n", "", $q);
        stopBecause("DB query failed. {$q}", 202);
    }
    return $result;
}