2018年5月9日 星期三

CSS3 rotate角度单位

弧度(Radians)。一个圆共2π弧度
90deg = 100grad = 0.25turn ≈ 1.570796326794897rad

2018年5月1日 星期二

jq.css 相關有用函示

(function () {
    let rcssNum = /^(?:([+-])=|)([+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|))([a-z%]*)$/i;
    rcssNum = /^(?:([+-])=)?(\-{0,1}(?:\d+|\d+\.\d+))([a-z%]*)$/i;

    let rmsPrefix = /^-ms-/;
    let rdashAlpha = /-([a-z])/g;

    let rcustomProp = /^--/;

    let cssNumber = {
        animationIterationCount: true,
        columnCount: true,
        fillOpacity: true,
        flexGrow: true,
        flexShrink: true,
        fontWeight: true,
        lineHeight: true,
        opacity: true,
        order: true,
        orphans: true,
        widows: true,
        zIndex: true,
        zoom: true
    };
    //==========================================================================
    // Convert dashed to camelCase; used by the css and data modules
    // Support: IE <=9 - 11, Edge 12 - 13
    // Microsoft forgot to hump their vendor prefix (#9572)
    function camelCase(string) {

        // rmsPrefix = /^-ms-/
        // rdashAlpha = /-([a-z])/g
        return string.replace(rmsPrefix, "ms-").replace(rdashAlpha, fcamelCase);
    }
    //==========================================================================

    // Return a property mapped along what jQuery.cssProps suggests or to
    // a vendor prefixed property.
    function finalPropName(name) {
        // jQuery.cssProps = {float: }
        var ret = jQuery.cssProps[name];
        if (!ret) {
            ret = jQuery.cssProps[name] = vendorPropName(name) || name;
        }
        return ret;
    }
    //==========================================================================

    // Return a css property mapped to a potentially vendor prefixed property
    // 針對不同瀏覽器的 prefixes
    function vendorPropName(name) {

        // Shortcut for names that are not vendor prefixed
        // emptyStyle
        if (name in emptyStyle) {
            return name;
        }

        // Check for vendor prefixed names
        var capName = name[0].toUpperCase() + name.slice(1),
                i = cssPrefixes.length;

        while (i--) {
            name = cssPrefixes[i] + capName;
            if (name in emptyStyle) {
                return name;
            }
        }
    }
    //==========================================================================

    function style(elem, name, value, extra) {
        debugger;

        // Don't set styles on text and comment nodes
        // nodeType:(3:text, 8:comment)
        if (!elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style) {
            return;
        }

        // Make sure that we're working with the right name
        var ret, type, hooks;
        var origName = jQuery.camelCase(name);

        // rcustomProp:/^--/
        var isCustomProp = rcustomProp.test(name);
        var style = elem.style;

        // Make sure that we're working with the right name. We don't
        // want to query the value if it is a CSS custom property
        // since they are user-defined.
        // 名稱的統一與修正
        if (!isCustomProp) {
            name = finalPropName(origName);
        }

        // Gets hook for the prefixed version, then unprefixed version
        hooks = jQuery.cssHooks[name] || jQuery.cssHooks[origName];

        // Check if we're setting a value
        if (value !== undefined) {
            debugger;

            type = typeof value;

            // Convert "+=" or "-=" to relative numbers (#7345)
            if (type === "string" && (ret = rcssNum.exec(value)) && ret[1]) {
                // here
                value = adjustCSS(elem, name, ret);

                // Fixes bug #9237
                type = "number";
            }

            // Make sure that null and NaN values aren't set (#7116)
            if (value == null || value !== value) {
                return;
            }

            // If a number was passed in, add the unit (except for certain CSS properties)
            if (type === "number") {
                value += ret && ret[3] || (jQuery.cssNumber[origName] ? "" : "px");
            }

            // background-* props affect original clone's values
            if (!support.clearCloneStyle && value === "" && name.indexOf("background") === 0) {
                style[name] = "inherit";
            }

            // If a hook was provided, use that value, otherwise just set the specified value
            if (!hooks || !("set" in hooks) ||
                    (value = hooks.set(elem, value, extra)) !== undefined) {

                if (isCustomProp) {
                    style.setProperty(name, value);
                } else {
                    style[name] = value;
                }
            }

        } else {

            // If a hook was provided get the non-computed value from there
            if (hooks && "get" in hooks &&
                    (ret = hooks.get(elem, false, extra)) !== undefined) {

                return ret;
            }

            // Otherwise just get the value from the style object
            return style[name];
        }
    }

    //==========================================================================
    // elem: dom
    // prop: cssKey
    // valueParts(單位與數值)
    function adjustCSS(elem, prop, valueParts, tween) {
        debugger;

        var adjusted;
        var scale = 1;
        var maxIterations = 20;

        //----------------------------
        // 獲取現在的值
        var currentValue = tween ?
                function () {
                    return tween.cur();
                } :
                function () {
                    return jQuery.css(elem, prop, "");
                };
        var initial = currentValue();
        //----------------------------
        // 設定的單位
        let unit;

        if (valueParts && valueParts[3]) {
            unit = valueParts[3];
        } else {
            unit = (jQuery.cssNumber[prop] ? "" : "px");
        }
        //----------------------------
        // 預設單位
        // Starting value computation is required for potential unit mismatches
        var initialInUnit = (jQuery.cssNumber[prop] || unit !== "px" && +initial);

        if (initialInUnit) {
            initialInUnit = rcssNum.exec(jQuery.css(elem, prop));
        }

        //----------------------------
        // 若預設單位與設定單位不同
        // 必須進入轉換
        if (initialInUnit && initialInUnit[3] !== unit) {

            // Trust units reported by jQuery.css
            unit = unit || initialInUnit[3];

            // Make sure we update the tween properties later on
            valueParts = valueParts || [];

            // Iteratively approximate from a nonzero starting point
            initialInUnit = +initial || 1;

            do {

                // If previous iteration zeroed out, double until we get *something*.
                // Use string for doubling so we don't accidentally see scale as unchanged below
                scale = scale || ".5";

                // Adjust and apply
                initialInUnit = initialInUnit / scale;
                jQuery.style(elem, prop, initialInUnit + unit);

                // Update scale, tolerating zero or NaN from tween.cur()
                // Break the loop if scale is unchanged or perfect, or if we've just had enough.
            } while (
                    (function () {
                        debugger;
                        let c_value = currentValue();
                        let a = scale;

                        // initial(一開始的值)
                        // 用目標單位移動後,取比例值,供下次修正
                        let b = scale = (c_value / initial);

                        return (a !== b) && (scale !== 1) && --maxIterations;
                    })()
                    );
        }
        //----------------------------
        if (valueParts) {
            initialInUnit = +initialInUnit || +initial || 0;

            // Apply relative offset (+=/-=) if specified
            adjusted = valueParts[1] ?
                    initialInUnit + (valueParts[1] + 1) * valueParts[2] :
                    +valueParts[2];
            if (tween) {
                tween.unit = unit;
                tween.start = initialInUnit;
                tween.end = adjusted;
            }
        }
        return adjusted;
    }
    ;
})();

2018年4月28日 星期六

將 matrix 轉換成 scale, rotate



function getMatrix(dom) {
            debugger;

            let css = window.getComputedStyle(dom);

            let _matrix = css['transform'];



            if (/none/i.test(_matrix)) {
                // 若沒有設定 matrix
                $(dom).css({
                    transform: 'scale(1)'
                });
                // debugger;
                _matrix = css['transform'];
            }


            // 每一deg=幾度
            let RAD_TO_DEG = 180 / Math.PI;

            let reg = /matrix\((.*)\)/;

            let res = reg.exec(_matrix);
            _matrix = res[1];

            let matrix = [[],[]];
            let position = [];

            _matrix = _matrix.split(',');

            for (let i = 0; i < _matrix.length; i++) {
                let m = Math.floor(i/2);
                let n = i % 2;

                let value = _matrix[i].replace(/^\s*|\s*$/g, '');
                value = parseFloat(value, 10);
                if(i < 4){
                    matrix[m][n] = value
                }else{
                    position.push(value);
                }
            }

            console.dir(matrix);
            console.dir(position);



            return {
                translate: {
                    x: (e + 'px'),
                    y: (f + 'px')
                },
                rotate: (rotate + 'deg'),
                scale: {
                    x: scaleX,
                    y: scaleY
                }
            }
        }

2018年4月26日 星期四

php 小技巧

※判斷是否開啟頁面,catch

if (ob_get_level() == 0) {
    // 尚未啟動 ob_start
    ob_start();
}
-----------------------------------------------
※判斷是否啟用 session

if (!isset($_SESSION)) {           
            session_start();
 }
-----------------------------------------------

2018年4月20日 星期五

js 模版的麻煩處......


let data = [];
let x = 'lllll"{{d}}"2222';

let fn = doIt(x);

let res = fn([9],textRender);
console.dir(res);


function doIt(str) {
    let pathList = [];

    str.replace(/{{([^\{\}]*?)}}/g, function (match, g_1) {
        // 取得所有變數名稱
        // 以後可以訂定修正規則
        g_1 = g_1.trim();
        pathList.push(g_1);
        data.push(g_1);
        return '';
    });

    /*--------------------------*/
// 組織 render 函式
    let content = [];
    let contentList = str.split(/{{[^\{\}]*?}}/g);

    for (let i = 0; i < contentList.length; i++) {
        let text = contentList[i];
        text = JSON.stringify(text);
        content.push(text);
        if (typeof pathList[i] !== 'undefined') {
            let variable = '(textRender(data[' + i + ']))';
            content.push(variable);
        }
    }
    if (content.length) {
        tempContent = "let str = " + content.join('+') + ";return str;";
        content.length = 0;
    } else {
        tempContent = 'return ""';
    }

    console.log('tempContent = %s', tempContent);

// 取得 render 函式
    let renderFn = new Function('data', 'textRender', tempContent);

    return renderFn;
}

function textRender(str) {
    debugger;
    let res = str;
    if (str == null) {
        res = '';
    } else if (typeof str === 'object') {
        res = JSON.stringify(str);
    }
    return res;
}






2018年4月19日 星期四

php printf

/**
 *
    %% - 返回一個百分號 %
    %b - 二進制數
    %c - ASCII 值對應的字符
    %d - 包含正負號的十進制數(負數、0、正數)
    %e - 使用小寫的科學計數法(例如 1.2e+2)
    %E - 使用大寫的科學計數法(例如 1.2E+2)
    %u - 不包含正負號的十進制數(大於等於 0)
    %f - 浮點數(本地設置)
    %F - 浮點數(非本地設置)
    %g - 較短的 %e 和 %f
    %G - 較短的 %E 和 %f
    %o - 八進制數
    %s - 字符串
    %x - 十六進制數(小寫字母)
    %X - 十六進制數(大寫字母)
 */

understand_codeigniter









js 仿製 php (serialize)






















module.exports = serialize;

function serialize(data) {
    let res = '';

    for (let i = 0, method; method = serialize.methods[i]; i++) {
        let temp;
        try {
            temp = method(data);
            res = temp;
            break;
        } catch (error) {
            if (error instanceof TypeError) {
                continue;
            } else {
                throw error;
            }
        }
    }
    return res;
}
//==============================================================================
(function (self) {

    self.methods = [
        function (data) {
            // string
            if (typeof data !== 'string') {
                throw new TypeError();
            }
            let res = 'String:' + String(data.length) + ':"' + data + '"';
            return res;
        },
        function (data) {
            // number
            if (typeof data !== 'number') {
                throw new TypeError();
            }
            let res = 'Number:' + data;
            return res;
        },
        function (data) {
            // undefined
            if (typeof data !== 'undefined') {
                throw new TypeError();
            }
            let res = 'undefined';
            return res;
        },
        function (data) {
            // null
            if (data !== null) {
                throw new TypeError();
            }
            let res = 'null';
            return res;
        },
        function (data) {
            // array
            if (!Array.isArray(data)) {
                throw new TypeError();
            }
            //----------------------------
            let res = 'Array:' + data.length + ':{';

            for (let i = 0; i < data.length; i++) {
                res += 'Number:' + i + ';';

                // 進入遞迴
                let _res = serialize(data[i]);

                res += _res + ';'
            }
            res += '}';

            return res;
        },
        //============================
        function (data) {
            // {}

            if (typeof data !== 'object' && data == null) {
                throw new TypeError();
            }
            let type = Object.prototype.toString.call(data);

            if (!/\[object Object\]/.test(data)) {
                throw new TypeError();
            }
            //----------------------------
            let length = Object.keys(data).length;
            let res = 'Object:' + length + ':{';

            for (let k in data) {
                if (data.hasOwnProperty(k)) {
                    // 進入遞迴
                    let _k = serialize(k);
                    let _res = serialize(data[k]);

                    res += _k + ';' + _res + ';';
                }
            }
            res += '}';

            return res;
        },
        //============================
        function (data) {
            // Map
            if (!(data instanceof Map)) {
                throw new TypeError();
            }

            let length = data.size;
            let res = 'Map:' + length + ':{';

            data.forEach(function (v, k) {
                // 進入遞迴
                k = serialize(k);
                v = serialize(v);

                res += (k + ';' + v + ';');
            });

            res += '}';

            return res;
        },
        function (data) {
            // 從函式實例化的物件
        }
    ];
})(serialize);
///////////////////////////////////////////////////////////////////////////////////////////
module.exports = unserialize;

function unserialize(data) {
    ++unserialize.count;
    //----------------------------
    let res;

    let objectType;

    data.replace(/^([^\:]+)/g, function (m, g) {
        objectType = g;
    });

    if (objectType in unserialize.methos) {
        res = unserialize.methos[objectType](data);
    } else {
        throw new Error(JSON.stringify(data) + ' no this method');
    }
    //----------------------------
    if (--unserialize.count === 0) {
        unserialize.jobs.length = 0;
    }

    return res;
}

(function (self) {
    self.UID = Math.floor(Math.random() * 0x10000000000).toString(16);

    self.count = 0;

    self.jobs = [];
    //==========================================================================
    // 從變數陣列中區分出 key, value
    self.getKeyValue = function (child_str) {

        // 避開 string 的影響
        // 清除所有 string 內部的內容,避免干擾發生
        child_str = self.prevProccessingString(child_str);
        // console.log(child_str);
        //----------------------------
        // 找尋屬於他的變數
        let str_variables = [];

        // 從左往右解
        while (child_str.length > 0) {
            let judge = 0;

            for (let i = 0; i < child_str.length; i++) {
                let char = child_str.charAt(i);

                if (char === '{') {
                    ++judge;
                }

                if (char === '}') {
                    --judge;
                }

                if ((char === ';' || i === (child_str.length - 1)) && judge === 0) {
                    // 取出一個區段
                    let target = child_str.slice(0, i + 1);
                    str_variables.push(target);
                    child_str = child_str.slice(i + 1);
                    break;
                }
            }
        }
        let res = {
            key: [],
            value: []
        };

        str_variables.forEach(function (v, i) {
            if (i % 2 === 0) {
                res.key.push(v);
            } else {
                res.value.push(v);
            }
        });

        return res;
    };
    //==========================================================================
    self.checkString = function (str) {


        let reg = new RegExp('@_' + unserialize.UID + '_(\\d+)_@');

        while (reg.test(str)) {
            res = reg.exec(str);
            let i = Number(res[1]);

            if (typeof unserialize.jobs[i] !== 'undefined') {
                let s = unserialize.jobs[i];
                str = str.replace(reg, s);

            } else {
                throw new Error('no find match string recorder');
            }
        }
        return str;
    };
    //==========================================================================
    // 這邊要加強
    // 對 unicode......等的加強
    self.prevProccessingString = function (str) {

        let res, reg = /String:(\d+):"/g;
        let positionList = [];

        while (res = reg.exec(str)) {
            // 匹配的字數
            let i = res[0].length;

            // 匹配的位置
            let index = res.index;

            // 文字的長度
            let length = parseInt(res[1], 10);

            if (length === 0) {
                // 沒有內容就不需處理
                continue;
            }

            let data = {
                s: (index + i),
                e: (index + i + length - 1)
            };

            data.target = str.slice(data.s, data.e + 1);

            positionList.unshift(data);
            // console.log(res);
        }

        positionList.forEach(function (d) {
            let start = d.s;
            let end = d.e;

            let index = unserialize.jobs.length;
            let replace = '@_' + unserialize.UID + '_' + index + '_@';


            let head = str.slice(0, start);
            let foot = str.slice(end + 1);
            let middle = str.slice(start, end + 1);

            unserialize.jobs[index] = middle;

            str = head + replace + foot;
        });

        return str;
    };
    //==========================================================================
    self.methos = {
        String: function (data) {
            let res = /"(.*)"/.exec(data);
            return res[1];
        },
        //======================================
        Number: function (data) {
            let res = /Number:(\d*)/.exec(data);
            return Number(res[1]);
        },
        //======================================
        Object: function (data) {
            let res = {};

            // 物件本身的描述
            let self_str = '';
            // 孩子的描述
            let child_str;
            let keyLength = 0;

            data.replace(/^([^\{\}]+?)\{(.*)\}/g, function (m, g1, g2) {
                self_str = g1;
                child_str = (g2 == null ? '' : g2);
                return '';
            });
            //----------------------------

            self_str.replace(/^[^:\d]+:(\d+):/g, function (m, g1) {
                keyLength = Number(g1);
            });
            //----------------------------           
            let d = self.getKeyValue(child_str);

            let keyList = d.key;
            let valueList = d.value;

            // 變數長度檢查
            if (keyLength !== keyList.length || keyList.length !== valueList.length) {
                throw new Error(data + ' variable length have trouble');
            }
            //----------------------------
            keyList.forEach(function (k, i) {
                console.dir(data);

                let v = valueList[i];
                k = unserialize.checkString(k);
                v = unserialize.checkString(v);

                // 遞迴
                k = unserialize(k);
                v = unserialize(v);

                res[k] = v;
            });

            //----------------------------
            if (keyLength !== Object.keys(res).length) {
                throw new Error("analyze error(" + data + ")");
            }
            return res;
        },
        //======================================
        Map: function (data) {
            let res = new Map();

            // 物件本身的描述
            let self_str = '';
            // 孩子的描述
            let child_str;
            let keyLength = 0;

            data.replace(/^([^\{\}]+?)\{(.*)\}/g, function (m, g1, g2) {
                self_str = g1;
                child_str = (g2 == null ? '' : g2);
                return '';
            });
            //----------------------------

            self_str.replace(/^[^:\d]+:(\d+):/g, function (m, g1) {
                keyLength = Number(g1);
            });
            //----------------------------           
            let d = self.getKeyValue(child_str);

            // console.dir(d);

            let keyList = d.key;
            let valueList = d.value;

            // 變數長度檢查
            if (keyLength !== keyList.length || keyList.length !== valueList.length) {
                throw new Error(data + ' variable length have trouble');
            }

            keyList.forEach(function (k, i) {
                let v = valueList[i];

                k = unserialize.checkString(k);
                v = unserialize.checkString(v);

                // 遞迴
                k = unserialize(k);
                v = unserialize(v);

                res.set(k, v);
            });
            //----------------------------
            return res;
        },
        Array: function (data) {
            let res = [];

            // 物件本身的描述
            let self_str = '';
            // 孩子的描述
            let child_str;
            let keyLength = 0;

            data.replace(/^([^\{\}]+?)\{(.*)\}/g, function (m, g1, g2) {
                self_str = g1;
                child_str = (g2 == null ? '' : g2);
                return '';
            });
            //----------------------------

            self_str.replace(/^[^:\d]+:(\d+):/g, function (m, g1) {
                keyLength = Number(g1);
            });
            //----------------------------           
            let d = self.getKeyValue(child_str);

            // console.dir(d);

            let keyList = d.key;
            let valueList = d.value;

            // 變數長度檢查
            if (keyLength !== keyList.length || keyList.length !== valueList.length) {
                throw new Error(data + ' variable length have trouble');
            }

            keyList.forEach(function (k, i) {
                let v = valueList[i];

                k = unserialize.checkString(k);
                v = unserialize.checkString(v);

                // 遞迴
                k = unserialize(k);
                v = unserialize(v);

                res[k] = v;
            });
            //----------------------------
            return res;
        },
        O: function (data) {
            // 非預設物件
            // 從函式實例化的物件
        },
    }
})(unserialize);

2018年4月12日 星期四

CodeIgniter(getBaseUrl())

function getBaseUrl() {
    $path = $_SERVER['SCRIPT_NAME'];
    $serverName = $_SERVER['SERVER_NAME'];
    $port = $_SERVER['SERVER_PORT'];

    $path = preg_replace("/\/index.*/i", '', $path);

    $baseUrl = sprintf('%s:%s%s', $serverName, $port, $path);
    return $baseUrl;
}

2018年4月7日 星期六

js htmlEntity

function htmlEntity() {
            var p = document.createElement("p");
            p.textContent = str;
            var converted = p.innerHTML;
            p = undefined;

            return converted;
        }

2018年3月7日 星期三

php 層層 include

>> root.php

i am root.php

include_once './inc_folder_1/inc_1.php';
 -----------------------------------------------------------
>> inc_1.php

i am inc_1.php

 include_once(__DIR__.'/inc_folder_2/inc_2.php');
 -----------------------------------------------------------
>> inc_2.php

i am inc_2.php

2018年2月22日 星期四

ConnectDB

<?php

interface ConnectDB {

    public function connect($database); // 連線

    public function selectDB($database);

    public function query($sql);

    public function fetchArray(); // 返回陣列

    public function fetchObjArray(); // 返回物件

    public function fetchOneArray($column = FALSE);

    public function fetchKeyArray($keyWord = null);

    public function Insert2DB($sql); // 專門用於插入資料用(會返回 insert_id)

    public function getInsertId();

    public function freeResult(); // 釋放結果的記憶體

    public function closeConnect();

    public function autoCommit($option);

    public function getConnect(); // 返回連線

    public function getResult(); // 返回查詢結果

    public function getColumn(); // 返回所有查詢後的欄位

    public function numOfRows();
}

?>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ConnectDBMyli
 *
 * @author test
 */
class ConnectDBMyli implements ConnectDB {

    protected $insert_id;
    protected $user;
    protected $psw;
    protected $url;
    protected $dataBase;
    protected $conn;
    protected $result;
    protected $errorMsg;

    /* ---------------------------------------------------------------------- */

    public function __construct() {
       
    }

    /* ---------------------------------------------------------------------- */

    public function setUser($user) {
        $this->user = $user;
    }

    /* ====================================================================== */

    public function setPsw($psw) {
        $this->psw = $psw;
    }

    /* ====================================================================== */

    public function setUrl($url) {
        $this->url = $url;
    }

    /* ====================================================================== */

    public function connect($database, $url = NULL, $user = NULL, $psw = NULL) {
        if ($url) {
            $this->setUrl($url);
        }

        if ($user) {
            $this->setUser($user);
        }

        if ($psw) {
            $this->setPsw($psw);
        }
        /* ------------------------------------------ */
        $this->dataBase = $database;

        $this->conn = @new mysqli($this->url, $this->user, $this->psw, $this->dataBase);

        if (mysqli_connect_errno() != 0) {

            $this->errorMsg = sprintf("connect error: %s", mysqli_connect_error());

            throw new Exception($this->errorMsg);
        }
        /* ------------------------------------------ */

        if (!($this->result = @$this->conn->query("SET NAMES 'utf8'"))) {

            $this->errorMsg = sprintf("set names error: %s", $this->conn->error);

            // throw new Exception($this->errorMsg);
        }
    }

    /* ====================================================================== */

    /**
     * 在建立連結之後,選擇 dataBase
     *
     * {@inheritDoc}
     * @see ConnectDB::selectDB()
     */
    public function selectDB($database) {
        $conn = $this->conn;

        $conn->select_db($database);
    }

    /* ====================================================================== */

    /**
     * 查詢
     *
     * {@inheritDoc}
     * @see ConnectDB::query()
     */
    public function query($sql) {
        $conn = $this->conn;


        if (!($this->result = $conn->query($sql))) {

            $this->errorMsg = sprintf("query error: %s", $this->conn->error);

            throw new Exception($this->errorMsg);
        }
    }

    /* ====================================================================== */

    public function fetchArray() {
        $data_arry = array();

        $result = $this->result;

        while (($row_data = $result->fetch_array()) !== null) {
           
           
            $data_arry[] = $row_data;
        }
    
        return $data_arry;
    }

    /* ====================================================================== */

    public function fetchObjArray() {
        $data_arry = array();

        $result = $this->result;

        while (($obj = $result->fetch_object()) !== null) {
            $data_arry[] = $obj;
        }

        return $data_arry;
    }

    /* ====================================================================== */

    /**
     * 只取出一個欄位的值
     */
    public function fetchOneColumnArray($column = FALSE) {
        $data_arry = array();
        $result = $this->result;
        $column = strtolower($column);


        while (($row_data = $result->fetch_array()) !== null) {

            foreach ($row_data as $k => $v) {
                if ($column === strtolower($k)) {

                    $data_arry[] = $v;
                }
            }
        }

        $this->freeResult();

        return $data_arry;
    }

    /* ====================================================================== */

    public function Insert2DB($sql) {
        $conn = $this->conn;

        if (!($this->result = $conn->query($sql))) {
            $this->errorMsg = sprintf("query error: %s", $this->conn->error);
            throw new Exception($this->errorMsg);
        }

        $insert_id = $conn->insert_id;

        $this->freeResult();

        return $insert_id;
    }

    /* ====================================================================== */

    public function autoCommit($option) {
       
    }

    /* ====================================================================== */

    public function closeConnect() {
        $this->conn->close();
    }

    /* ---------------------------------------------------------------------- */

    public function fetchKeyArray($keyWord = null) {
        $result_array = array();
        $result = $this->result;

        if ($keyWord === null) {
            // 若沒有給 key,則用預設的查詢回應
            $result_array = fetchArray();
        } else {
            while (($row_data = $result->fetch_array()) !== null) {

                if (isset($row_data[$keyWord])) {
                    $result_array[$row_data[$keyWord]] = $row_data;
                }
            }
        }

        return $result_array;
    }

    /* ---------------------------------------------------------------------- */

    public function fetchOneArray($column = FALSE) {
        $result = $this->result;

        $row_data = $result->fetch_array();

        if ($column) {
            return $row_data[$column];
        }

        $this->freeResult();

        return $row_data;
    }

    /* ---------------------------------------------------------------------- */

    public function freeResult() {
        $this->result->close();
    }

    /* ---------------------------------------------------------------------- */

    public function getInsertId() {
        $conn = $this->conn;

        return $conn->insert_id;
    }

    /* ---------------------------------------------------------------------- */

    public function getConnect() {
       
    }

    /* ---------------------------------------------------------------------- */

    public function getResult() {
       
    }

    /* ---------------------------------------------------------------------- */

    public function getColumn() {
        $column_array = array();
        $result = $this->result;

        $column_array = $result->fetch_field();

        return $column_array;
    }

    public function numOfRows() {
        $result = $this->result;
        return $result->num_rows;
    }

}