• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    一個訪問ACCESS的類

    發布: 2007-7-14 19:53 | 作者: 佚名    | 來源: 網絡轉載     | 查看: 10次 | 進入軟件測試論壇討論

    領測軟件測試網 這是ACCESS的類

    <?
    Class AccessDBM
    {
        var $COUNT = 0;
        var $VALUES = array();
        var $FILE = "";
        var $ERROR = "";
        var $EXISTS = false;
        var $STATIC = false;
        var $EXACT = false;
        var $DBM;

    //    Older version of PHP can't do the 'new ClassName(args)'
    //    Use initilize() if this is the case.

    //    *******************************************************

        function AccessDBM ($dbmFile, $static = 0)
        {
            global $php_errormsg;

            if(!empty($dbmFile))
            {
                if(file_exists($dbmFile))
                {
                    $this->EXISTS = true;
                }
                if($static != 0)
                {
                    $this->STATIC = true;
                }
                $this->FILE = $dbmFile;
            }
            return;
        }

    //    *******************************************************

    //    Identical to AccessDBM
        function initialize ($dbmFile, $static = 0)
        {
            global $php_errormsg;

            if(!empty($dbmFile))
            {
                if(file_exists($dbmFile))
                {
                    $this->EXISTS = true;
                }
                if($static != 0)
                {
                    $this->STATIC = true;
                }
                $this->FILE = $dbmFile;
            }
            return;
        }

    //    *******************************************************

        function add_entry ($key, $val)
        {
            $results = 0;
            $dbm = $this->open_dbm();
            if(!$dbm) { return false; }

            if(!(dbmreplace($dbm,$key,$val)))
            {
                if(!(dbmexists($dbm,$key)))
                {
                    $this->ERROR = "Fatal error : could not replace $key with $val";
                    $this->close_dbm($dbm);
                    return false;
                }
            }
            $this->close_dbm($dbm);
            return true;        
        }

    //    *******************************************************

        function remove_entry ($Key)
        {
            global $php_errormsg;
            $removed = false;

            $dbm = $this->open_dbm();
            if(!$dbm) { return false; }

            if(dbmexists($dbm,$Key))
            {
                if(!dbmdelete($dbm,$Key))
                {
                    if(dbmexists($dbm,$Key))
                    {
                        $this->ERROR = "Unable to remove [$Key] : [$php_errormsg]";
                        $this->close_dbm($dbm);
                        return false;
                    }
                }
                else
                {
                    $this->close_dbm($dbm);
                    $removed = true;
                }
            }
            else
            {
                $this->ERROR = "Key [$Key] does not exist";
                $this->close_dbm($dbm);
                return false;
            }
            return true;
        }

    //    *******************************************************

        function get_value ($Key)
        {
            $val = "";
            $readOnly = true;

            $dbm = $this->open_dbm($readOnly);

            if(!$dbm) { return false; }

            if(dbmexists($dbm,$Key))
            {
                $val = dbmfetch($dbm,$Key);
            }
            $this->close_dbm($dbm);
            return $val;
        }

    //    *******************************************************

        function open_dbm ($readOnly = false)
        {
            global $php_errormsg;

            if($this->STATIC)
            {
                if(!(empty($this->DBM)))
                {
                    $dbm = $this->DBM;
                    return ($dbm);
                }
            }

            $fileName = $this->FILE;

            if(!$this->EXISTS)
            {
                $dbm = @dbmopen($fileName,"n");
            }
            else
            {
                if(!$readOnly)
                {
                    // We want the warning here if we can't be
                    // a writer
                    $dbm = dbmopen($fileName,"w");
                }
                else
                {
                    $dbm = @dbmopen($fileName,"r");
                }
            }
            if( (!$dbm) or (empty($dbm)) )
            {
                $this->EXISTS = false;
                $this->STATIC = false;
                $this->ERROR = "Unable to open [$fileName] [$php_errormsg]";
                return false;
            }
            $this->EXISTS = true;
            if($this->STATIC)
            {
                $this->DBM = $dbm;
            }

            return ($dbm);

        }

    //    *******************************************************

        function find_key ($search)
        {
            $val = "";

            $dbm = $this->open_dbm(1);
            if(!$dbm) { return false; }
            if(dbmexists($dbm,$search))
            {
                // Wow an exact match
                $val = dbmfetch($dbm,$search);
                $this->close_dbm($dbm);
                $this->EXACT = true;
                return $val;
            }
            else
            {
                $this->EXACT = false;
                $key = dbmfirstkey($dbm);
                while ($key)
                {
                    // Strip the first whitespace char and
                    // everything after it.
                    $test = ereg_replace(" .*","",$key);
                    if(eregi("^$test",$search))
                    {
                        $val = dbmfetch($dbm,$key);
                        $this->close_dbm($dbm);
                        error_log("Test [$test] matched [$search]",0);
                        return $val;
                    }
                    $key = dbmnextkey($dbm,$key);
                }
            }
            // Didn't find it
            $this->close_dbm($dbm);
            return false;
        }

    //    *******************************************************

        // Returns the KEY
        function find_val ($search)
        {
            $this->EXACT = false;

            $Dbase = $this->get_all();
            if(empty($Dbase))
            {
                error_log("ERROR Dbase is empty $DB->ERROR",0);
                return false;
            }
            while ( list ( $key, $val ) = each ($Dbase) )
            {
                if($search == $val)
                {
                    $this->EXACT=true;
                    return $key;
                }
                else
                {
                    // Strip the first whitespace char and
                    // everything after it.

                    $test = ereg_replace(" .*","",$val);

                    if(eregi("^$test",$search))
                    {
                        $this->EXACT = false;
                        return $key;
                    }
                }
            }
            // Didn't find it
            return false;
        }

    //    *******************************************************

        function get_all ()
        {
            $values = array();
            $count = 0;
            $readOnly = true;
            $dbm = $this->open_dbm($readOnly);
            if(!$dbm) { return false; }

            $key = dbmfirstkey($dbm);

            while ($key)
            {
                $val = dbmfetch($dbm,$key);
                $values[$key] = $val;
                $count++;
                $key = dbmnextkey($dbm, $key);
            }
            $this->COUNT = $count;
            $this->VALUES = $values;
            $this->close_dbm($dbm);
            return $values;
        }

    //    *******************************************************

        function close_dbm ($dbm)
        {
            $results = false;

            if(!$this->STATIC)
            {
                $results = dbmclose($dbm);
            }
            return $results;
        }


    //    *******************************************************

        function static_close()
        {
            $results = false;

            if(!$this->DBM)
            {
                $this->ERROR = "No static DBM to close";
                return false;
            }
            $dbm = $this->DBM;
            $results = dbmclose($dbm);
            unset($this->DBM);
            return $results;
        }

    //    *******************************************************

    }
    ?>

    這個連接上!
    include("class.AccessDBM.php3");
        $static = true;
        $dbase = new AccessDBM("/path/to/file.dbm",$static);


        register_shutdown_function($dbase->static_close());


        if(!$dbase->add_entry("cdi","cdi@thewebmasters.net))
        {
            echo "Error adding entry: $dbase->ERROR\n";
        }
        $Values = $dbase->get_all()
        while ( list ($key,$val) = each ($Values) )
        {
            echo "Key: $key  Val: $val \n";
        }
        exit;

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>