选择显示字体大小

国外好东西真的多,现在贴上一个访问access的类!


   这是access的类

<?
class accessdbm
{
    var &#36;count = 0;
    var &#36;values = array();
    var &#36;file = &quot;&quot;;
    var &#36;error = &quot;&quot;;
    var &#36;exists = false;
    var &#36;static = false;
    var &#36;exact = false;
    var &#36;dbm;

//    older version of php can&#39;t do the &#39;new classname(args)&#39;
//    use initilize() if this is the case.

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

    function accessdbm (&#36;dbmfile, &#36;static = 0)
    {
        global &#36;php_errormsg;

        if(!empty(&#36;dbmfile))
        {
            if(file_exists(&#36;dbmfile))
            {
                &#36;this->exists = true;
            }
            if(&#36;static != 0)
            {
                &#36;this->static = true;
            }
            &#36;this->file = &#36;dbmfile;
        }
        return;
    }

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

//    identical to accessdbm
    function initialize (&#36;dbmfile, &#36;static = 0)
    {
        global &#36;php_errormsg;

        if(!empty(&#36;dbmfile))
        {
            if(file_exists(&#36;dbmfile))
            {
                &#36;this->exists = true;
            }
            if(&#36;static != 0)
            {
                &#36;this->static = true;
            }
            &#36;this->file = &#36;dbmfile;
        }
        return;
    }

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

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

        if(!(dbmreplace(&#36;dbm,&#36;key,&#36;val)))
        {
            if(!(dbmexists(&#36;dbm,&#36;key)))
            {
                &#36;this->error = &quot;fatal error : could not replace &#36;key with &#36;val&quot;;
                &#36;this->close_dbm(&#36;dbm);
                return false;
            }
        }
        &#36;this->close_dbm(&#36;dbm);
        return true;        
    }

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

    function remove_entry (&#36;key)
    {
        global &#36;php_errormsg;
        &#36;removed = false;

        &#36;dbm = &#36;this->open_dbm();
        if(!&#36;dbm) { return false; }

        if(dbmexists(&#36;dbm,&#36;key))
        {
            if(!dbmdelete(&#36;dbm,&#36;key))
            {
                if(dbmexists(&#36;dbm,&#36;key))
                {
                    &#36;this->error = &quot;unable to remove [&#36;key] : [&#36;php_errormsg]&quot;;
                    &#36;this->close_dbm(&#36;dbm);
                    return false;
                }
            }
            else
            {
                &#36;this->close_dbm(&#36;dbm);
                &#36;removed = true;
            }
        }
        else
        {
            &#36;this->error = &quot;key [&#36;key] does not exist&quot;;
            &#36;this->close_dbm(&#36;dbm);
            return false;
        }
        return true;
    }

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

    function get_value (&#36;key)
    {
        &#36;val = &quot;&quot;;
        &#36;readonly = true;

        &#36;dbm = &#36;this->open_dbm(&#36;readonly);

        if(!&#36;dbm) { return false; }

        if(dbmexists(&#36;dbm,&#36;key))
        {
            &#36;val = dbmfetch(&#36;dbm,&#36;key);
        }
        &#36;this->close_dbm(&#36;dbm);
        return &#36;val;
    }

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

    function open_dbm (&#36;readonly = false)
    {
        global &#36;php_errormsg;

        if(&#36;this->static)
        {
            if(!(empty(&#36;this->dbm)))
            {
                &#36;dbm = &#36;this->dbm;
                return (&#36;dbm);
            }
        }

        &#36;filename = &#36;this->file;

        if(!&#36;this->exists)
        {
            &#36;dbm = @dbmopen(&#36;filename,&quot;n&quot;);
        }
        else
        {
            if(!&#36;readonly)
            {
                // we want the warning here if we can&#39;t be
                // a writer
                &#36;dbm = dbmopen(&#36;filename,&quot;w&quot;);
            }
            else
            {
                &#36;dbm = @dbmopen(&#36;filename,&quot;r&quot;);
            }
        }
        if( (!&#36;dbm) or (empty(&#36;dbm)) )
        {
            &#36;this->exists = false;
            &#36;this->static = false;
            &#36;this->error = &quot;unable to open [&#36;filename] [&#36;php_errormsg]&quot;;
            return false;
        }
        &#36;this->exists = true;
        if(&#36;this->static)
        {
            &#36;this->dbm = &#36;dbm;
        }

        return (&#36;dbm);

    }

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

    function find_key (&#36;search)
    {
        &#36;val = &quot;&quot;;

        &#36;dbm = &#36;this->open_dbm(1);
        if(!&#36;dbm) { return false; }
        if(dbmexists(&#36;dbm,&#36;search))
        {
            // wow an exact match
            &#36;val = dbmfetch(&#36;dbm,&#36;search);
            &#36;this->close_dbm(&#36;dbm);
            &#36;this->exact = true;
            return &#36;val;
        }
        else
        {
            &#36;this->exact = false;
            &#36;key = dbmfirstkey(&#36;dbm);
            while (&#36;key)
            {
                // strip the first whitespace char and
                // everything after it.
                &#36;test = ereg_replace(&quot; .*&quot;,&quot;&quot;,&#36;key);
                if(eregi(&quot;^&#36;test&quot;,&#36;search))
                {
                    &#36;val = dbmfetch(&#36;dbm,&#36;key);
                    &#36;this->close_dbm(&#36;dbm);
                    error_log(&quot;test [&#36;test] matched [&#36;search]&quot;,0);
                    return &#36;val;
                }
                &#36;key = dbmnextkey(&#36;dbm,&#36;key);
            }
        }
        // didn&#39;t find it
        &#36;this->close_dbm(&#36;dbm);
        return false;
    }

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

    // returns the key
    function find_val (&#36;search)
    {
        &#36;this->exact = false;

        &#36;dbase = &#36;this->get_all();
        if(empty(&#36;dbase))
        {
            error_log(&quot;error dbase is empty &#36;db->error&quot;,0);
            return false;
        }
        while ( list ( &#36;key, &#36;val ) = each (&#36;dbase) )
        {
            if(&#36;search == &#36;val)
            {
                &#36;this->exact=true;
                return &#36;key;
            }
            else
            {
                // strip the first whitespace char and
                // everything after it.

                &#36;test = ereg_replace(&quot; .*&quot;,&quot;&quot;,&#36;val);

                if(eregi(&quot;^&#36;test&quot;,&#36;search))
                {
                    &#36;this->exact = false;
                    return &#36;key;
                }
            }
        }
        // didn&#39;t find it
        return false;
    }

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

    function get_all ()
    {
        &#36;values = array();
        &#36;count = 0;
        &#36;readonly = true;
        &#36;dbm = &#36;this->open_dbm(&#36;readonly);
        if(!&#36;dbm) { return false; }

        &#36;key = dbmfirstkey(&#36;dbm);

        while (&#36;key)
        {
            &#36;val = dbmfetch(&#36;dbm,&#36;key);
            &#36;values[&#36;key] = &#36;val;
            &#36;count++;
            &#36;key = dbmnextkey(&#36;dbm, &#36;key);
        }
        &#36;this->count = &#36;count;
        &#36;this->values = &#36;values;
        &#36;this->close_dbm(&#36;dbm);
        return &#36;values;
    }

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

    function close_dbm (&#36;dbm)
    {
        &#36;results = false;

        if(!&#36;this->static)
        {
            &#36;results = dbmclose(&#36;dbm);
        }
        return &#36;results;
    }


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

    function static_close()
    {
        &#36;results = false;

        if(!&#36;this->dbm)
        {
            &#36;this->error = &quot;no static dbm to close&quot;;
            return false;
        }
        &#36;dbm = &#36;this->dbm;
        &#36;results = dbmclose(&#36;dbm);
        unset(&#36;this->dbm);
        return &#36;results;
    }

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

}
?>

这个连接上!
include(&quot;class.accessdbm.php3&quot;);
    &#36;static = true;
    &#36;dbase = new accessdbm(&quot;/path/to/file.dbm&quot;,&#36;static);


    register_shutdown_function(&#36;dbase->static_close());


    if(!&#36;dbase->add_entry(&quot;cdi&quot;,&quot;cdi@thewebmasters.net))
    {
        echo &quot;error adding entry: &#36;dbase->error\n&quot;;
    }
    &#36;values = &#36;dbase->get_all()
    while ( list (&#36;key,&#36;val) = each (&#36;values) )
    {
        echo &quot;key: &#36;key  val: &#36;val \n&quot;;
    }
    exit;


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons