[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_handlers/ -> mysql_class.php (source)

   1  <?php
   2  
   3  /*
   4  +---------------------------------------------------------------+
   5  |     e107 website system
   6  |
   7  |     ©Steve Dunstan 2001-2002
   8  |     http://e107.org
   9  |     jalist@e107.org
  10  |
  11  |     Released under the terms and conditions of the
  12  |     GNU General Public License (http://gnu.org).
  13  |
  14  |     $Source: /cvsroot/e107/e107_0.7/e107_handlers/mysql_class.php,v $
  15  |     $Revision: 1.65 $
  16  |     $Date: 2007/02/07 21:24:58 $
  17  |     $Author: e107steved $
  18  +----------------------------------------------------------------------------+
  19  */
  20  
  21  if (!defined('e107_INIT')) { exit; }
  22  
  23  $db_time = 0.0;                // Global total time spent in all db object queries
  24  $db_mySQLQueryCount = 0;    // Global total number of db object queries (all db's)
  25  
  26  /**
  27  * MySQL Abstraction class
  28  *
  29  * @package e107
  30  * @version $Revision: 1.65 $
  31  * @author $Author: e107steved $
  32  */
  33  class db {
  34  
  35      var $mySQLserver;
  36      var $mySQLuser;
  37      var $mySQLpassword;
  38      var $mySQLdefaultdb;
  39      var $mySQLaccess;
  40      var $mySQLresult;
  41      var $mySQLrows;
  42      var $mySQLerror;
  43      var $mySQLcurTable;
  44      var $mySQLlanguage;
  45      var $mySQLinfo;
  46      var $tabset;
  47  
  48      /**
  49      * @return db
  50      * @desc db constructor gets language options from the cookie or session
  51      * @access public
  52      */
  53      function db() {
  54          global $pref, $eTraffic;
  55          $eTraffic->BumpWho('Create db object', 1);
  56          $langid = 'e107language_'.$pref['cookie_name'];
  57          if ($pref['user_tracking'] == 'session') {
  58              if (!isset($_SESSION[$langid])) { return; }
  59              $this->mySQLlanguage = $_SESSION[$langid];
  60          } else {
  61              if (!isset($_COOKIE[$langid])) { return; }
  62              $this->mySQLlanguage = $_COOKIE[$langid];
  63          }
  64      }
  65  
  66      /**
  67      * @return null or string error code
  68      * @param string $mySQLserver IP Or hostname of the MySQL server
  69      * @param string $mySQLuser MySQL username
  70      * @param string $mySQLpassword MySQL Password
  71      * @param string $mySQLdefaultdb The database schema to connect to
  72      * @desc Connects to mySQL server and selects database - generally not required if your table is in the main DB.<br />
  73      * <br />
  74      * Example using e107 database with variables defined in config.php:<br />
  75      * <code>$sql = new db;
  76      * $sql->db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);</code>
  77      * <br />
  78      * OR to connect an other database:<br />
  79      * <code>$sql = new db;
  80      * $sql->db_Connect('url_server_database', 'user_database', 'password_database', 'name_of_database');</code>
  81      *
  82      * @access public
  83      */
  84  	function db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb) {
  85          global $eTraffic;
  86          $eTraffic->BumpWho('db Connect', 1);
  87  
  88          $this->mySQLserver = $mySQLserver;
  89          $this->mySQLuser = $mySQLuser;
  90          $this->mySQLpassword = $mySQLpassword;
  91          $this->mySQLdefaultdb = $mySQLdefaultdb;
  92  
  93          $temp = $this->mySQLerror;
  94          $this->mySQLerror = FALSE;
  95          if(defined("USE_PERSISTANT_DB") && USE_PERSISTANT_DB == true){
  96              if (!$this->mySQLaccess = @mysql_pconnect($this->mySQLserver, $this->mySQLuser, $this->mySQLpassword)) {
  97                  return 'e1';
  98              } else {
  99                  if (!@mysql_select_db($this->mySQLdefaultdb)) {
 100                      return 'e2';
 101                  } else {
 102                      $this->dbError('dbConnect/SelectDB');
 103                  }
 104              }
 105          } else {
 106              if (!$this->mySQLaccess = @mysql_connect($this->mySQLserver, $this->mySQLuser, $this->mySQLpassword)) {
 107                  return 'e1';
 108              } else {
 109                  if (!@mysql_select_db($this->mySQLdefaultdb)) {
 110                      return 'e2';
 111                  } else {
 112                      $this->dbError('dbConnect/SelectDB');
 113                  }
 114              }
 115          }
 116      }
 117  
 118      /**
 119      * @return void
 120      * @param unknown $sMarker
 121      * @desc Enter description here...
 122      * @access private
 123      */
 124  	function db_Mark_Time($sMarker) {
 125          if (E107_DEBUG_LEVEL > 0) {
 126              global $db_debug;
 127              $db_debug->Mark_Time($sMarker);
 128          }
 129      }
 130  
 131      /**
 132      * @return void
 133      * @desc Enter description here...
 134      * @access private
 135      */
 136  	function db_Show_Performance() {
 137          return $db_debug->Show_Performance();
 138      }
 139  
 140      /**
 141      * @return void
 142      * @desc add query to dblog table
 143      * @access private
 144      */
 145  	function db_Write_log($log_type = '', $log_remark = '', $log_query = '') {
 146          global $tp, $e107;
 147          $d = time();
 148          $uid = (USER) ? USERID : '0';
 149          $ip = $e107->getip();
 150          $qry = $tp->toDB($log_query);
 151          $this->db_Insert('dblog', "0, '{$log_type}', {$d}, {$uid}, '{$ip}', '{$qry}', '{$log_remark}'");
 152      }
 153  
 154      /**
 155      * @return unknown
 156      * @param unknown $query
 157      * @param unknown $rli
 158      * @desc Enter description here...
 159      * @access private
 160      */
 161  	function db_Query($query, $rli = NULL, $qry_from = '', $debug = FALSE, $log_type = '', $log_remark = '') {
 162          global $db_time,$db_mySQLQueryCount,$queryinfo, $eTraffic;
 163          $db_mySQLQueryCount++;
 164  
 165          if ($debug == 'now') {
 166              echo "** $query";
 167          }
 168          if ($debug !== FALSE || strstr(e_QUERY, 'showsql'))
 169          {
 170              $queryinfo[] = "<b>{$qry_from}</b>: $query";
 171          }
 172          if ($log_type != '') {
 173              $this->db_Write_log($log_type, $log_remark, $query);
 174          }
 175  
 176          $b = microtime();
 177          $sQryRes = is_null($rli) ? @mysql_query($query) : @mysql_query($query, $rli);
 178          $e = microtime();
 179  
 180          $eTraffic->Bump('db_Query', $b, $e);
 181          $mytime = $eTraffic->TimeDelta($b,$e);
 182          $db_time += $mytime;
 183          $this->mySQLresult = $sQryRes;
 184          if (E107_DEBUG_LEVEL) {
 185              global $db_debug;
 186              $aTrace = debug_backtrace();
 187              $pTable = $this->mySQLcurTable;
 188              if (!strlen($pTable)) {
 189                  $pTable = '(complex query)';
 190              } else {
 191                  $this->mySQLcurTable = ''; // clear before next query
 192              }
 193              if(is_object($db_debug)) {
 194                  $nFields = $db_debug->Mark_Query($query, $rli, $sQryRes, $aTrace, $mytime, $pTable);
 195              } else {
 196                  echo "what happened to db_debug??!!<br />";
 197              }
 198          }
 199          return $sQryRes;
 200      }
 201  
 202      /**
 203      * @return int Number of rows or false on error
 204      *
 205      * @param string $table Table name to select data from
 206      * @param string $fields Table fields to be retrieved, default * (all in table)
 207      * @param string $arg Query arguments, default null
 208      * @param string $mode Argument has WHERE or not, default=default (WHERE)
 209      *
 210      * @param bool $debug Debug mode on or off
 211      *
 212      * @desc Perform a mysql_query() using the arguments suplied by calling db::db_Query()<br />
 213      * <br />
 214      * If you need more requests think to call the class.<br />
 215      * <br />
 216      * Example using a unique connection to database:<br />
 217      * <code>$sql->db_Select("comments", "*", "comment_item_id = '$id' AND comment_type = '1' ORDER BY comment_datestamp");</code><br />
 218      * <br />
 219      * OR as second connection:<br />
 220      * <code>$sql2 = new db;
 221      * $sql2->db_Select("chatbox", "*", "ORDER BY cb_datestamp DESC LIMIT $from, ".$view, 'no_where');</code>
 222      *
 223      * @access public
 224      */
 225  	function db_Select($table, $fields = '*', $arg = '', $mode = 'default', $debug = FALSE, $log_type = '', $log_remark = '') {
 226          global $db_mySQLQueryCount;
 227          $table = $this->db_IsLang($table);
 228          $this->mySQLcurTable = $table;
 229          if ($arg != '' && $mode == 'default')
 230          {
 231              if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.MPREFIX.$table.' WHERE '.$arg, NULL, 'db_Select', $debug, $log_type, $log_remark)) {
 232                  $this->dbError('dbQuery');
 233                  return $this->db_Rows();
 234              } else {
 235                  $this->dbError("db_Select (SELECT $fields FROM ".MPREFIX."{$table} WHERE {$arg})");
 236                  return FALSE;
 237              }
 238          } elseif ($arg != '' && $mode != 'default') {
 239              if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.MPREFIX.$table.' '.$arg, NULL, 'db_Select', $debug, $log_type, $log_remark)) {
 240                  $this->dbError('dbQuery');
 241                  return $this->db_Rows();
 242              } else {
 243                  $this->dbError("db_Select (SELECT {$fields} FROM ".MPREFIX."{$table} {$arg})");
 244                  return FALSE;
 245              }
 246          } else {
 247              if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.MPREFIX.$table, NULL, 'db_Select', $debug, $log_type, $log_remark)) {
 248                  $this->dbError('dbQuery');
 249                  return $this->db_Rows();
 250              } else {
 251                  $this->dbError("db_Select (SELECT {$fields} FROM ".MPREFIX."{$table})");
 252                  return FALSE;
 253              }
 254          }
 255      }
 256  
 257      /**
 258      * @return int Last insert ID or false on error
 259      * @param string $table
 260      * @param string $arg
 261      * @param string $debug
 262      * @desc Insert a row into the table<br />
 263      * <br />
 264      * Example:<br />
 265      * <code>$sql->db_Insert("links", "0, 'News', 'news.php', '', '', 1, 0, 0, 0");</code>
 266      *
 267      * @access public
 268      */
 269  	function db_Insert($table, $arg, $debug = FALSE, $log_type = '', $log_remark = '') {
 270          $table = $this->db_IsLang($table);
 271          $this->mySQLcurTable = $table;
 272          if(is_array($arg))
 273          {
 274              $keyList= "`".implode("`,`", array_keys($arg))."`";
 275              $valList= "'".implode("','", $arg)."'";
 276              $query = "INSERT INTO `".MPREFIX."{$table}` ({$keyList}) VALUES ({$valList})";
 277          }
 278          else
 279          {
 280              $query = 'INSERT INTO '.MPREFIX."{$table} VALUES ({$arg})";
 281          }
 282  
 283          if ($result = $this->mySQLresult = $this->db_Query($query, NULL, 'db_Insert', $debug, $log_type, $log_remark )) {
 284              $tmp = mysql_insert_id();
 285              return $tmp;
 286          } else {
 287              $this->dbError("db_Insert ($query)");
 288              return FALSE;
 289          }
 290      }
 291  
 292      /**
 293      * @return int number of affected rows, or false on error
 294      * @param string $table
 295      * @param string $arg
 296      * @param bool $debug
 297      * @desc Update fields in ONE table of the database corresponding to your $arg variable<br />
 298      * <br />
 299      * Think to call it if you need to do an update while retrieving data.<br />
 300      * <br />
 301      * Example using a unique connection to database:<br />
 302      * <code>$sql->db_Update("user", "user_viewed='$u_new' WHERE user_id='".USERID."' ");</code>
 303      * <br />
 304      * OR as second connection<br />
 305      * <code>$sql2 = new db;
 306      * $sql2->db_Update("user", "user_viewed = '$u_new' WHERE user_id = '".USERID."' ");</code><br />
 307      *
 308      * @access public
 309      */
 310  	function db_Update($table, $arg, $debug = FALSE, $log_type = '', $log_remark = '') {
 311          $table = $this->db_IsLang($table);
 312          $this->mySQLcurTable = $table;
 313          if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.MPREFIX.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark)) {
 314              $result = mysql_affected_rows();
 315              if ($result == -1) return FALSE;    // Error return from mysql_affected_rows
 316              return $result;
 317          } else {
 318              $this->dbError("db_Update ($query)");
 319              return FALSE;
 320          }
 321      }
 322  
 323      /**
 324      * @return array MySQL row
 325      * @param string $mode
 326      * @desc Fetch an array containing row data (see PHP's mysql_fetch_array() docs)<br />
 327      * <br />
 328      * Example :<br />
 329      * <code>while($row = $sql->db_Fetch()){
 330      *  $text .= $row['username'];
 331      * }</code>
 332      *
 333      * @access public
 334      */
 335  	function db_Fetch() {
 336          global $eTraffic;
 337          $b = microtime();
 338          $row = @mysql_fetch_array($this->mySQLresult);
 339          $eTraffic->Bump('db_Fetch', $b);
 340          if ($row) {
 341              $this->dbError('db_Fetch');
 342              return $row;
 343          } else {
 344              $this->dbError('db_Fetch');
 345              return FALSE;
 346          }
 347      }
 348  
 349      /**
 350      * @return int number of affected rows or false on error
 351      * @param string $table
 352      * @param string $fields
 353      * @param string $arg
 354      * @desc Count the number of rows in a select<br />
 355      * <br />
 356      * Example:<br />
 357      * <code>$topics = $sql->db_Count("forum_t", "(*)", " WHERE thread_forum_id='".$forum_id."' AND thread_parent='0' ");</code>
 358      *
 359      * @access public
 360      */
 361  	function db_Count($table, $fields = '(*)', $arg = '', $debug = FALSE, $log_type = '', $log_remark = '') {
 362          $table = $this->db_IsLang($table);
 363  
 364          if ($fields == 'generic') {
 365              $query=$table;
 366              if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Count', $debug, $log_type, $log_remark)) {
 367                  $rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult);
 368                  return $rows['COUNT(*)'];
 369              } else {
 370                  $this->dbError("dbCount ($query)");
 371                  return FALSE;
 372              }
 373          }
 374  
 375          $this->mySQLcurTable = $table;
 376          $query='SELECT COUNT'.$fields.' FROM '.MPREFIX.$table.' '.$arg;
 377          if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Count', $debug, $log_type, $log_remark)) {
 378              $rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult);
 379              return $rows[0];
 380          } else {
 381              $this->dbError("dbCount ($query)");
 382              return FALSE;
 383          }
 384      }
 385  
 386      /**
 387      * @return void
 388      * @desc Closes the mySQL server connection.<br />
 389      * <br />
 390      * Only required if you open a second connection.<br />
 391      * Native e107 connection is closed in the footer.php file<br />
 392      * <br />
 393      * Example :<br />
 394      * <code>$sql->db_Close();</code>
 395      *
 396      * @access public
 397      */
 398  	function db_Close() {
 399          global $eTraffic;
 400          $eTraffic->BumpWho('db Close', 1);
 401          mysql_close();
 402          $this->dbError('dbClose');
 403      }
 404  
 405      /**
 406      * @return int number of affected rows, or false on error
 407      * @param string $table
 408      * @param string $arg
 409      * @desc Delete rows from a table<br />
 410      * <br />
 411      * Example:
 412      * <code>$sql->db_Delete("tmp", "tmp_ip='$ip'");</code><br />
 413      * <br />
 414      * @access public
 415      */
 416  	function db_Delete($table, $arg = '', $debug = FALSE, $log_type = '', $log_remark = '') {
 417          $table = $this->db_IsLang($table);
 418          $this->mySQLcurTable = $table;
 419          if (!$arg) {
 420              if ($result = $this->mySQLresult = $this->db_Query('DELETE FROM '.MPREFIX.$table, NULL, 'db_Delete', $debug, $log_type, $log_remark)) {
 421                  return $result;
 422              } else {
 423                  $this->dbError("db_Delete ($arg)");
 424                  return FALSE;
 425              }
 426          } else {
 427              if ($result = $this->mySQLresult = $this->db_Query('DELETE FROM '.MPREFIX.$table.' WHERE '.$arg, NULL, 'db_Delete', $debug, $log_type, $log_remark)) {
 428                  $tmp = mysql_affected_rows();
 429                  return $tmp;
 430              } else {
 431                  $this->dbError('db_Delete ('.$arg.')');
 432                  return FALSE;
 433              }
 434          }
 435      }
 436  
 437      /**
 438      * @return unknown
 439      * @desc Enter description here...
 440      * @access private
 441      */
 442  	function db_Rows() {
 443          $rows = $this->mySQLrows = @mysql_num_rows($this->mySQLresult);
 444          return $rows;
 445          $this->dbError('db_Rows');
 446      }
 447  
 448      /**
 449      * @return unknown
 450      * @param unknown $from
 451      * @desc Enter description here...
 452      * @access private
 453      */
 454  	function dbError($from) {
 455          if ($error_message = @mysql_error()) {
 456              if ($this->mySQLerror == TRUE) {
 457                  message_handler('ADMIN_MESSAGE', '<b>mySQL Error!</b> Function: '.$from.'. ['.@mysql_errno().' - '.$error_message.']', __LINE__, __FILE__);
 458                  return $error_message;
 459              }
 460          }
 461      }
 462  
 463      /**
 464      * @return void
 465      * @param unknown $mode
 466      * @desc Enter description here...
 467      * @access private
 468      */
 469  	function db_SetErrorReporting($mode) {
 470          $this->mySQLerror = $mode;
 471      }
 472  
 473  
 474      /**
 475      * @return unknown
 476      * @param unknown $arg
 477      * @desc Enter description here...
 478      * @access private
 479      */
 480  	function db_Select_gen($query, $debug = FALSE, $log_type = '', $log_remark = '') {
 481  
 482          /*
 483          changes by jalist 19/01/05:
 484          added string replace on table prefix to tidy up long database queries
 485          usage: instead of sending "SELECT * FROM ".MPREFIX."table", do "SELECT * FROM #table"
 486          */
 487  
 488          $this->tabset = FALSE;
 489          if(strpos($query,'#') !== FALSE) {
 490              $query = preg_replace_callback("/\s#([\w]*?)\W/", array($this, 'ml_check'), $query);
 491          }
 492          if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Select_gen', $debug, $log_type, $log_remark)) {
 493              $this->dbError('db_Select_gen');
 494              return $this->db_Rows();
 495          } else {
 496              $this->dbError('dbQuery ('.$query.')');
 497              return FALSE;
 498          }
 499      }
 500  
 501  	function ml_check($matches) {
 502          $table = $this->db_IsLang($matches[1]);
 503          if($this->tabset == false) {
 504              $this->mySQLcurTable = $table;
 505              $this->tabset = true;
 506          }
 507          return " ".MPREFIX.$table.substr($matches[0],-1);
 508      }
 509  
 510      /**
 511      * @return unknown
 512      * @param unknown $offset
 513      * @desc Enter description here...
 514      * @access private
 515      */
 516  	function db_Fieldname($offset) {
 517          $result = @mysql_field_name($this->mySQLresult, $offset);
 518          return $result;
 519      }
 520  
 521      /**
 522      * @return unknown
 523      * @desc Enter description here...
 524      * @access private
 525      */
 526  	function db_Field_info() {
 527          $result = @mysql_fetch_field($this->mySQLresult);
 528          return $result;
 529      }
 530  
 531      /**
 532      * @return unknown
 533      * @desc Enter description here...
 534      * @access private
 535      */
 536  	function db_Num_fields() {
 537          $result = @mysql_num_fields($this->mySQLresult);
 538          return $result;
 539      }
 540  
 541      /**
 542      * @return unknown
 543      * @param unknown $table
 544      * @desc Enter description here...
 545      * @access private
 546      */
 547  	function db_IsLang($table,$multiple=FALSE) {
 548          global $pref, $mySQLtablelist;
 549          if ((!$this->mySQLlanguage || !$pref['multilanguage']) && $multiple==FALSE) {
 550                return $table;
 551          }
 552  
 553          if (!$mySQLtablelist) {
 554              $tablist = mysql_list_tables($this->mySQLdefaultdb);
 555              while (list($temp) = mysql_fetch_array($tablist)) {
 556                  $mySQLtablelist[] = $temp;
 557              }
 558          }
 559  
 560          $mltable = "lan_".strtolower($this->mySQLlanguage.'_'.$table);
 561  
 562      // ---- Find all multi-language tables.
 563  
 564          if($multiple == TRUE){ // return an array of all matching language tables. eg [french]->e107_lan_news
 565              if(!is_array($table)){
 566                  $table = array($table);
 567              }
 568  
 569              foreach($mySQLtablelist as $tab){
 570                   if(stristr($tab, MPREFIX."lan_") !== FALSE){
 571                      $tmp = explode("_",str_replace(MPREFIX."lan_","",$tab));
 572                         $lng = $tmp[0];
 573                      foreach($table as $t){
 574                          if(eregi($t."$",$tab)){
 575                              $lanlist[$lng][MPREFIX.$t] = $tab;
 576                          }
 577                      }
 578                    }
 579              }
 580              return ($lanlist) ? $lanlist : FALSE;
 581          }
 582      // -------------------------
 583  
 584          if (in_array(MPREFIX.$mltable, $mySQLtablelist)) {
 585              return $mltable;
 586          }
 587           return $table;
 588      }
 589  
 590      /**
 591      * @return array
 592      * @param string fields to retrieve
 593      * @desc returns fields as structured array
 594      * @access public
 595      */
 596  	function db_getList($fields = 'ALL', $amount = FALSE, $maximum = FALSE, $ordermode=FALSE) {
 597          $list = array();
 598          $counter = 1;
 599          while ($row = $this->db_Fetch()) {
 600              foreach($row as $key => $value) {
 601                  if (is_string($key)) {
 602                      if (strtoupper($fields) == 'ALL' || in_array ($key, $fields)) {
 603  
 604                          if(!$ordermode)
 605                          {
 606                              $list[$counter][$key] = $value;
 607                          }
 608                          else
 609                          {
 610                              $list[$row[$ordermode]][$key] = $value;
 611                          }
 612                      }
 613                  }
 614              }
 615              if ($amount && $amount == $counter || ($maximum && $counter > $maximum)) {
 616                  break;
 617              }
 618              $counter++;
 619          }
 620          return $list;
 621      }
 622  
 623      /**
 624      * @return integer
 625      * @desc returns total number of queries made so far
 626      * @access public
 627      */
 628  	function db_QueryCount() {
 629          global $db_mySQLQueryCount;
 630          return $db_mySQLQueryCount;
 631      }
 632  
 633  
 634      /*
 635          Multi-language Query Function.
 636      */
 637  
 638  
 639  	function db_Query_all($query,$debug=""){
 640          $error = "";
 641  
 642          $query = str_replace("#",MPREFIX,$query);
 643  
 644          if(!$this->db_Query($query)){  // run query on the default language first.
 645              $error .= $query. " failed";
 646          }
 647  
 648          $tmp = explode(" ",$query);
 649            foreach($tmp as $val){
 650                 if(strpos($val,MPREFIX) !== FALSE){
 651                  $table[] = str_replace(MPREFIX,"",$val);
 652                  $search[] = $val;
 653              }
 654          }
 655  
 656       // Loop thru relevant language tables and replace each tablename within the query.
 657          if($tablist = $this->db_IsLang($table,TRUE)){
 658              foreach($tablist as $key=>$tab){
 659                  $querylan = $query;
 660                  foreach($search as $find){
 661                      $lang = $key;
 662                      $replace = ($tab[$find] !="") ? $tab[$find] : $find;
 663                           $querylan = str_replace($find,$replace,$querylan);
 664                  }
 665  
 666                  if(!$this->db_Query($querylan)){ // run query on other language tables.
 667                      $error .= $querylan." failed for language";
 668                  }
 669                   if($debug){ echo "<br />** lang= ".$querylan; }
 670              }
 671          }
 672  
 673  
 674          return ($error)? FALSE : TRUE;
 675      }
 676  
 677      // Determines if a plugin field (and key) exist. OR if fieldid is numeric - return the field name in that position.
 678      function db_Field($table,$fieldid="",$key=""){
 679          if(!$this->mySQLdefaultdb){
 680              global $mySQLdefaultdb;
 681              $this->mySQLdefaultdb = $mySQLdefaultdb;
 682          }
 683          $convert = array("PRIMARY"=>"PRI","INDEX"=>"MUL","UNIQUE"=>"UNI");
 684          $key = ($convert[$key]) ? $convert[$key] : "OFF";
 685  
 686          $result = mysql_query("SHOW COLUMNS FROM ".MPREFIX.$table);
 687          if (mysql_num_rows($result) > 0) {
 688              $c=0;
 689                 while ($row = mysql_fetch_assoc($result)) {
 690                  if(is_numeric($fieldid))
 691                  {
 692                      if($c == $fieldid)
 693                      {
 694                         return $row['Field']; // field number matches.
 695                      }
 696                  }
 697                  else
 698                  {
 699                      if(($key == "") && ($fieldid == $row['Field']))
 700                      {
 701                          return TRUE;  // key not in use, but field matches.
 702                      }
 703                      elseif(($fieldid == $row['Field']) && $key == $row['Key'])
 704                      {
 705                          return TRUE;
 706                      }
 707  
 708                   }
 709                  $c++;
 710              }
 711          }
 712  
 713          return FALSE;
 714  
 715      }
 716  
 717      /**
 718       * A pointer to mysql_real_escape_string() - see http://www.php.net/mysql_real_escape_string
 719       *
 720       * @param string $data
 721       * @return string
 722       */
 723  	function escape($data, $strip = true) {
 724          if ($strip) {
 725              $data = strip_if_magic($data);
 726          }
 727          return mysql_real_escape_string($data);
 728      }
 729  }
 730  
 731  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7