[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/includes/functions/ -> database.php (source)

   1  <?php
   2  /*

   3  $Id: database.php 14 2006-07-28 17:42:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13    function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') {
  14      global $$link;
  15  
  16      if (USE_PCONNECT == 'true') {
  17        $$link = mysql_pconnect($server, $username, $password);
  18      } else {
  19        $$link = mysql_connect($server, $username, $password);
  20      }
  21  
  22      if ($$link) mysql_select_db($database);
  23  
  24      return $$link;
  25    }
  26  
  27    function tep_db_close($link = 'db_link') {
  28      global $$link;
  29  
  30      return mysql_close($$link);
  31    }
  32  
  33    function tep_db_error($query, $errno, $error) { 
  34      die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>');
  35    }
  36  
  37    function tep_db_query($query, $link = 'db_link') {
  38      global $$link, $logger;
  39  
  40      if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
  41        if (!is_object($logger)) $logger = new logger;
  42        $logger->write($query, 'QUERY');
  43      }
  44  
  45      $result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
  46  
  47      if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
  48        if (mysql_error()) $logger->write(mysql_error(), 'ERROR');
  49      }
  50  
  51      return $result;
  52    }
  53  
  54    function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
  55      reset($data);
  56      if ($action == 'insert') {
  57        $query = 'insert into ' . $table . ' (';
  58        while (list($columns, ) = each($data)) {
  59          $query .= $columns . ', ';
  60        }
  61        $query = substr($query, 0, -2) . ') values (';
  62        reset($data);
  63        while (list(, $value) = each($data)) {
  64          switch ((string)$value) {
  65            case 'now()':
  66              $query .= 'now(), ';
  67              break;
  68            case 'null':
  69              $query .= 'null, ';
  70              break;
  71            default:
  72              $query .= '\'' . tep_db_input($value) . '\', ';
  73              break;
  74          }
  75        }
  76        $query = substr($query, 0, -2) . ')';
  77      } elseif ($action == 'update') {
  78        $query = 'update ' . $table . ' set ';
  79        while (list($columns, $value) = each($data)) {
  80          switch ((string)$value) {
  81            case 'now()':
  82              $query .= $columns . ' = now(), ';
  83              break;
  84            case 'null':
  85              $query .= $columns .= ' = null, ';
  86              break;
  87            default:
  88              $query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
  89              break;
  90          }
  91        }
  92        $query = substr($query, 0, -2) . ' where ' . $parameters;
  93      }
  94  
  95      return tep_db_query($query, $link);
  96    }
  97  
  98    function tep_db_fetch_array($db_query) {
  99      return mysql_fetch_array($db_query, MYSQL_ASSOC);
 100    }
 101  
 102    function tep_db_result($result, $row, $field = '') {
 103      return mysql_result($result, $row, $field);
 104    }
 105  
 106    function tep_db_num_rows($db_query) {
 107      return mysql_num_rows($db_query);
 108    }
 109  
 110    function tep_db_data_seek($db_query, $row_number) {
 111      return mysql_data_seek($db_query, $row_number);
 112    }
 113  
 114    function tep_db_insert_id($link = 'db_link') {
 115      global $$link;
 116      return mysql_insert_id($$link);
 117    }
 118  
 119    function tep_db_free_result($db_query) {
 120      return mysql_free_result($db_query);
 121    }
 122  
 123    function tep_db_fetch_fields($db_query) {
 124      return mysql_fetch_field($db_query);
 125    }
 126  
 127    function tep_db_output($string) {
 128      return htmlspecialchars($string);
 129    }
 130  
 131  // LINE CHNAGED: MS2 update 501112 - Added "$link = 'db_link'"

 132    function tep_db_input($string, $link = 'db_link') {
 133  // BOF: MS2 update 501112-Added

 134      global $$link;
 135  
 136      if (function_exists('mysql_real_escape_string')) {
 137        return mysql_real_escape_string($string, $$link);
 138      } elseif (function_exists('mysql_escape_string')) {
 139        return mysql_escape_string($string);
 140      }
 141  // EOF: MS2 update 501112-Added

 142      return addslashes($string);
 143    }
 144  
 145    function tep_db_prepare_input($string) {
 146      if (is_string($string)) {
 147        return trim(stripslashes($string));
 148      } elseif (is_array($string)) {
 149        reset($string);
 150        while (list($key, $value) = each($string)) {
 151          $string[$key] = tep_db_prepare_input($value);
 152        }
 153        return $string;
 154      } else {
 155        return $string;
 156      }
 157    }
 158  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7