:::

4-3 function.php

<?php
//連上資料庫
function link_db()
{
    //實體化
    $mysqli = @new mysqli(_DB_LOCATON, _DB_ID, _DB_PASS, _DB_NAME);
    if ($mysqli->connect_error) {
        throw new Exception('無法連上資料庫:' . $mysqli->connect_error);
    }
    $mysqli->set_charset("utf8");
    return $mysqli;
}

//檢查並傳回欲拿到資料使用的變數
function clean_var($var = '', $title = '', $filter = '')
{
    global $db;
    $clean_var = $db->real_escape_string($_REQUEST[$var]);
    if (empty($clean_var)) {
        throw new Exception("{$title}為必填!");
    }
    if ($filter) {
        $clean_var = filter_var($clean_var, $filter);
        if (!$clean_var) {
            throw new Exception("不合法的{$title}");
        }
    }
    return $clean_var;
}

 


:::

書籍目錄

展開 | 闔起

快速登入


http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D777%26tbsn%3D28

計數器

今天: 1634163416341634
昨天: 4125412541254125
總計: 8044412804441280444128044412804441280444128044412