• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            老外用php寫的一個MySQL類

             

            Description:

            Extremely easy to 
            use and full-featured MySQL class with measured queries.
             

            Code
            :

            <?
            /*****************************************************************************/
            /*                                                                           */
            /*  mySQL Function Wrapper Class                                             */
            /*                                                                           */
            /*  (C) 2001 Thomas Wolf (two@DONTSPAMMEchello.at)                                     */
            /*                                                                           */
            /*  Wed 21 Nov 17:41:53 2001                                                 */
            /*  Thu 29 Nov 19:20:22 2001 -lu                                             */
            /*                                                                           */
            /*****************************************************************************/

            define("CMySQL_Included","1");

            class CMySQL
            {
                
            // default values
                var $def_host   = "localhost";  // default host name
                var $def_user   = "";   // default user name
                var $def_pass   = "";   // default password
                var $def_dbname = "service";  // default database name

                // class-internal variables

                var $linkid     = 0;   // mysql link id
                var $errstr     = "";   // last mysql error string
                var $lastsql    = "";   // last mysql query
                var $last_result;    // last mysql query result
                var $m_start    = 0;
                
            var $m_diff     = 0;

                
            /* Constructor:
                 *  Set default values and stuff.
                 
            */
                
            function CMySQL()
                {
                    
            $errstr = "no connection";
                }
                
            /* CMySQL->Open:
                 *  Connect to specified mySQL server.
                 
            */
                
            function Open($dbname="",$host="",$user="",$pass="",$pcon=0)
                {
                    
            // use defaults?
                    if (!$dbname$dbname = $this->def_dbname;
                    
            if (!$host  ) $host   = $this->def_host;
                    
            if (!$user  ) $user   = $this->def_user;
                    
            if (!$pass  ) $pass   = $this->def_pass;

                    
            // open persistent or normal connection
                    if ($pcon) {
                        
            $this->linkid = @mysql_pconnect($host,$user,$pass);
                    } 
            else {
                        
            $this->linkid = @mysql_connect ($host,$user,$pass);
                    }
                    
            // connect to mysql server failed?
                    if (!$this->linkid)
                    {
                        
            $this->errstr  = $pcon ? "persistent " : "";
                        
            $this->errstr .= "connect failed ('$user:$pass@$host')";
                        
            return 0// error
                    }
                    
            // select database
                    $result = mysql_select_db($dbname);
                    
            if (!$result)
                    {
                        
            // db select failed
                        @mysql_close($this->linkid);
                        
            $this->errstr = "database not found ('$dbname')";
                        
            return 0// error
                    }
                    
            // return with success
                    return 1;
                }
                
            /* CMySQL->Test:
                 *  Tests a database connection and returns
                 *  1 on success or 0 on error.
                 
            */
                
            function Test($dbname,$host="",$user="",$pass="")
                {
                    
            return $this->Open($dbname,$host,$user,$pass,0);
                }
                
            /* CMySQL->Error:
                 *  Returns the last mySQL error as text.
                 
            */
                
            function Error()
                {
                    
            if (!empty($this->errstr))
                        
            return $this->errstr."<br>\n";

                    
            if (empty($this->linkid))
                    {
                        
            $this->errstr = "no connection";
                        
            $em = $this->errstr;
                    }
                    
            else {
                        
            $en = @mysql_errno($this->linkid);
                        
            $em = @mysql_error($this->linkid);
                        
            if (!$en || !$em)
                        {
                            
            $this->errstr = "no connection";
                            
            $em = $this->errstr;
                            
            if (!$en$en = "0";
                        }
                    }
                    
            return "$em (#$en)<br>\n";
                }
                
            /* CMySQL->Kill:
                 *  Dies script with last mySQL error message.
                 
            */
                
            function Kill()
                {
                    
            die ($this->Error());
                }
                
            /* CMySQL->ErrorNum:
                 *  Returns the last mySQL error as number.
                 
            */
                
            function ErrorNum()
                {
                    
            return @mysql_errno($this->linkid);
                }
                
            /* CMySQL->Close:
                 *  Close current mySQL connection.
                 
            */
                
            function Close()
                {
                    
            return @mysql_close($this->linkid);
                }
                
            /* CMySQL->Query:
                 *  Executes the given SQL query and returns
                 *  the proper results.
                 
            */
                
            function Query($sql="")
                {
                    
            $this->lastsql = $sql;
                    
            $this->last_result = @mysql_query($sql,$this->linkid);
                    
            if (!$this->last_result)
                    {
                        
            $this->errstr = "query failed ('$sql')";
                        
            return 0// error
                    }
                    
            return $this->last_result;
                }
                
            /* CMySQL->QueryM:
                 *  Executes the given SQL query, measures
                 *  it and returns the proper results.
                 
            */
                
            function QueryM($sql="")
                {
                    
            $this->Start();
                    
            $result = $this->Query($sql);
                    
            $this->Stop();
                    
            return $result;
                }
                
            /* CMySQL->Start:
                 *  Starts time measurement.
                 
            */
                
            function Start()
                {
                    
            $parts = explode(" ",microtime());
                    
            $this->m_diff  = 0;
                    
            $this->m_start = $parts[1].substr($parts[0],1);
                }
                
            /* CMySQL->Stop:
                 *  Stops time measurement.
                 
            */
                
            function Stop()
                {
                    
            $parts  = explode(" ",microtime());
                    
            $m_stop = $parts[1].substr($parts[0],1);
                    
            $this->m_diff  = ($m_stop - $this->m_start);
                    
            $this->m_start = 0;
                }
                
            /* CMySQL->Duration:
                 *  Returns last measured duration (time
                 *  between Start() and Stop()).
                 
            */
                
            function Duration($decimals=4)
                {
                    
            return number_format($this->m_diff,$decimals);
                }
                
            /* CMySQL->Rows:
                 *  Returns the last query's number of rows.
                 
            */
                
            function Rows()
                {
                    
            if (!$this->last_result) return 0;
                    
            return @mysql_num_rows($this->last_result);
                }
                
            /* CMySQL->Fix:
                 *  Returns string suitable for mySQL queries.
                 
            */
                
            function Fix($str)
                {
                    
            return @addslashes($str);
                }
                
            /* CMySQL->Unfix:
                 *  Returns mySQL string as normal string.
                 
            */
                
            function Unfix($str)
                {
                    
            return @stripslashes($str);
                }
                
            /* CMySQL->Row:
                 *  Reads the current row and returns contents
                 *  as an PHP object or returns 0 on error.
                 
            */
                
            function Row()
                {
                    
            if ($this->last_result) {
                        
            $row = mysql_fetch_object($this->last_result);
                    } 
            else {
                        
            $row = 0;
                    }
                    
            return $row;
                }
                
            /* CMySQL->RowA:
                 *  Reads the current row and returns contents
                 *  as an array or returns 0 on error.
                 
            */
                
            function RowA()
                {
                    
            if ($this->last_result) {
                        
            $row = mysql_fetch_array($this->last_result);
                    } 
            else {
                        
            $row = 0;
                    }
                    
            return $row;
                }
                
            /* CMySQL->Seek:
                 *  Sets the internal database pointer to the
                 * specified row number and returns the result.
                 
            */
                
            function Seek($rownum)
                {
                    
            return mysql_data_seek($this->last_result,$rownum);
                }
                
            /* CMySQL->Free:
                 *  Frees memory used by the query results and
                 *  returns the function result.
                 
            */
                
            function Free()
                {
                    
            return @mysql_free_result($this->last_result);
                }
            }
            /*****************************************************************************/
            ?>

             

             

            posted on 2007-04-03 18:43 PeakGao 閱讀(473) 評論(0)  編輯 收藏 引用 所屬分類: 數(shù)據(jù)庫開發(fā) 、php

            <2007年3月>
            25262728123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(9)

            隨筆分類(67)

            隨筆檔案(65)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            97精品依人久久久大香线蕉97| 中文国产成人精品久久不卡| 国产精品永久久久久久久久久| 久久青青草原精品国产软件| 亚洲伊人久久成综合人影院| 久久精品久久久久观看99水蜜桃| 久久ZYZ资源站无码中文动漫| 香蕉久久一区二区不卡无毒影院| 久久久亚洲精品蜜桃臀| 久久亚洲春色中文字幕久久久| 精品久久久久久| 久久AV高潮AV无码AV| 99久久精品午夜一区二区| 国产呻吟久久久久久久92| 亚洲综合熟女久久久30p| 久久WWW免费人成—看片| 伊人久久大香线焦AV综合影院| 99久久99久久精品国产| 久久精品国产久精国产一老狼| 亚洲国产成人久久综合一 | 东京热TOKYO综合久久精品| 日韩精品无码久久一区二区三 | 国产免费久久精品丫丫| 亚洲AV无码1区2区久久| 久久久久亚洲AV无码专区网站| 97久久天天综合色天天综合色hd| 亚洲日韩欧美一区久久久久我| 99热都是精品久久久久久| 亚洲综合日韩久久成人AV| 7777精品伊人久久久大香线蕉| 91精品国产高清久久久久久国产嫩草| 亚洲中文字幕久久精品无码APP| 亚洲Av无码国产情品久久| 国产精品久久久天天影视香蕉 | 精品久久久久久久久久中文字幕 | 欧美一级久久久久久久大片| 国产亚洲精久久久久久无码| 亚洲精品午夜国产VA久久成人 | 91精品国产91久久久久久青草| 久久狠狠高潮亚洲精品| 亚洲AV日韩精品久久久久|