D:/XC2.1_alpha3/html/class/database/mysqldatabase.php

00001 <?php
00002 // $Id: mysqldatabase.php,v 1.2.8.5 2006/04/21 03:03:19 minahito Exp $
00003 //  ------------------------------------------------------------------------ //
00004 //                XOOPS - PHP Content Management System                      //
00005 //                    Copyright (c) 2000 XOOPS.org                           //
00006 //                       <http://www.xoops.org/>                             //
00007 //  ------------------------------------------------------------------------ //
00008 //  This program is free software; you can redistribute it and/or modify     //
00009 //  it under the terms of the GNU General Public License as published by     //
00010 //  the Free Software Foundation; either version 2 of the License, or        //
00011 //  (at your option) any later version.                                      //
00012 //                                                                           //
00013 //  You may not change or alter any portion of this comment or credits       //
00014 //  of supporting developers from this source code or any supporting         //
00015 //  source code which is considered copyrighted (c) material of the          //
00016 //  original comment or credit authors.                                      //
00017 //                                                                           //
00018 //  This program is distributed in the hope that it will be useful,          //
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
00021 //  GNU General Public License for more details.                             //
00022 //                                                                           //
00023 //  You should have received a copy of the GNU General Public License        //
00024 //  along with this program; if not, write to the Free Software              //
00025 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
00026 //  ------------------------------------------------------------------------ //
00027 // Author: Kazumi Ono (AKA onokazu)                                          //
00028 // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
00029 // Project: The XOOPS Project                                                //
00030 // ------------------------------------------------------------------------- //
00042 include_once XOOPS_ROOT_PATH."/class/database/database.php";
00043 
00055 class XoopsMySQLDatabase extends XoopsDatabase
00056 {
00061         var $conn;
00062 
00067         var $mPrepareQuery=null;
00068 
00075         function connect($selectdb = true)
00076         {
00077                 if (XOOPS_DB_PCONNECT == 1) {
00078                         $this->conn = @mysql_pconnect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS);
00079                 } else {
00080                         $this->conn = @mysql_connect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS);
00081                 }
00082         
00083                 if (!$this->conn) {
00084                         $this->logger->addQuery('', $this->error(), $this->errno());
00085                         return false;
00086                 }
00087                 
00088                 if($selectdb != false){
00089                         if (!mysql_select_db(XOOPS_DB_NAME)) {
00090                                 $this->logger->addQuery('', $this->error(), $this->errno());
00091                                 return false;
00092                         }
00093                 }
00094                 return true;
00095         }
00096 
00106         function genId($sequence)
00107         {
00108                 return 0; // will use auto_increment
00109         }
00110 
00117         function fetchRow($result)
00118         {
00119                 return @mysql_fetch_row($result);
00120         }
00121 
00127         function fetchArray($result)
00128     {
00129         return @mysql_fetch_assoc( $result );
00130     }
00131 
00137     function fetchBoth($result)
00138     {
00139         return @mysql_fetch_array( $result, MYSQL_BOTH );
00140     }
00141 
00147         function getInsertId()
00148         {
00149                 return mysql_insert_id($this->conn);
00150         }
00151 
00158         function getRowsNum($result)
00159         {
00160                 return @mysql_num_rows($result);
00161         }
00162 
00168         function getAffectedRows()
00169         {
00170                 return mysql_affected_rows($this->conn);
00171         }
00172 
00177         function close()
00178         {
00179                 mysql_close($this->conn);
00180         }
00181 
00188         function freeRecordSet($result)
00189         {
00190                 return mysql_free_result($result);
00191         }
00192 
00198         function error()
00199         {
00200                 return @mysql_error();
00201         }
00202 
00208         function errno()
00209         {
00210                 return @mysql_errno();
00211         }
00212 
00219     function quoteString($str)
00220     {
00221          $str = "'".str_replace('\\"', '"', addslashes($str))."'";
00222          return $str;
00223     }
00224 
00234     function &queryF($sql, $limit=0, $start=0)
00235         {
00236                 if ( !empty($limit) ) {
00237                         if (empty($start)) {
00238                                 $start = 0;
00239                         }
00240                         $sql = $sql. ' LIMIT '.(int)$start.', '.(int)$limit;
00241                 }
00242                 $result = mysql_query($sql, $this->conn);
00243                 if ( $result ) {
00244                         $this->logger->addQuery($sql);
00245                         return $result;
00246         } else {
00247                         $this->logger->addQuery($sql, $this->error(), $this->errno());
00248             $ret = false;
00249             return $ret;
00250         }
00251     }
00252 
00265         function &query($sql, $limit=0, $start=0)
00266         {
00267 
00268     }
00269 
00277         function queryFromFile($file){
00278         if (false !== ($fp = fopen($file, 'r'))) {
00279                         include_once XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php';
00280             $sql_queries = trim(fread($fp, filesize($file)));
00281             OldSqlUtility::splitMySqlFile($pieces, $sql_queries);
00282             foreach ($pieces as $query) {
00283                 // [0] contains the prefixed query
00284                 // [4] contains unprefixed table name
00285                 $prefixed_query = OldSqlUtility::prefixQuery(trim($query), $this->prefix());
00286                 if ($prefixed_query != false) {
00287                     $this->query($prefixed_query[0]);
00288                 }
00289             }
00290             return true;
00291         }
00292         return false;
00293     }
00294     
00302         function getFieldName($result, $offset)
00303         {
00304                 return mysql_field_name($result, $offset);
00305         }
00306 
00314     function getFieldType($result, $offset)
00315         {
00316                 return mysql_field_type($result, $offset);
00317         }
00318 
00325         function getFieldsNum($result)
00326         {
00327                 return mysql_num_fields($result);
00328         }
00329 
00330         function prepare($query)
00331         {
00332                 $count=0;
00333                 while(($pos=strpos($query,"?"))!==false) {
00334                         $pre=substr($query,0,$pos);
00335                         $after="";
00336                         if($pos+1<=strlen($query))
00337                                 $after=substr($query,$pos+1);
00338                                 
00339                         $query=$pre."{".$count."}".$after;
00340                         $count++;
00341                 }
00342                 $this->mPrepareQuery=$query;
00343         }
00344 
00345         function bind_param()
00346         {
00347                 if(func_num_args()<2)
00348                         return;
00349 
00350                 $types=func_get_arg(0);
00351                 $count=strlen($types);
00352                 if(func_num_args()<$count)
00353                         return;
00354 
00355                 $searches=array();
00356                 $replaces=array();
00357                 for($i=0;$i<$count;$i++) {
00358                         $searches[$i]="{".$i."}";
00359                         switch(substr($types,$i,1)) {
00360                                 case "i":
00361                                         $replaces[$i]=intval(func_get_arg($i+1));
00362                                         break;
00363 
00364                                 case "s":
00365                                         $replaces[$i]=$this->quoteString(func_get_arg($i+1));
00366                                         break;
00367 
00368                                 case "d":
00369                                         $replaces[$i]=doubleval(func_get_arg($i+1));
00370                                         break;
00371                                 
00372                                 case "b":
00373                                         // Exception
00374                                         die();
00375                         }
00376                 }
00377 
00378                 $this->mPrepareQuery=str_replace($searches,$replaces,$this->mPrepareQuery);
00379         }
00380 
00381         function &execute()
00382         {
00383                 $result=&$this->query($this->mPrepareQuery);
00384                 $this->mPrepareQuery=null;
00385                 return $result;
00386         }
00387 
00388         function &executeF()
00389         {
00390                 $result=&$this->queryF($this->mPrepareQuery);
00391                 $this->mPrepareQuery=null;
00392                 return $result;
00393         }
00394 }
00395 
00406 class XoopsMySQLDatabaseSafe extends XoopsMySQLDatabase
00407 {
00408 
00418         function &query($sql, $limit=0, $start=0)
00419         {
00420                 $result =& $this->queryF($sql, $limit, $start);
00421                 return $result;
00422         }
00423 }
00424 
00438 class XoopsMySQLDatabaseProxy extends XoopsMySQLDatabase
00439 {
00440 
00451         function &query($sql, $limit=0, $start=0)
00452         {
00453             $sql = ltrim($sql);
00454                 if (strtolower(substr($sql, 0, 6)) == 'select') {
00455                 //if (preg_match("/^SELECT.*/i", $sql)) {
00456                         $ret = $this->queryF($sql, $limit, $start);
00457                         return $ret;
00458                 }
00459                 $this->logger->addQuery($sql, 'Database update not allowed during processing of a GET request', 0);
00460                 
00461                 $ret = false;
00462                 return $ret;
00463         }
00464 }
00465 ?>

XoopsCubeに対してFri Aug 4 21:18:03 2006に生成されました。  doxygen 1.4.7