[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/system/ -> lib-database.php (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Geeklog 1.4                                                               |
   6  // +---------------------------------------------------------------------------+
   7  // | lib-database.php                                                          |
   8  // |                                                                           |
   9  // | Geeklog database library.                                                 |
  10  // +---------------------------------------------------------------------------+
  11  // | Copyright (C) 2000-2006 by the following authors:                         |
  12  // |                                                                           |
  13  // | Authors: Tony Bibbs, tony AT tonybibbs DOT com                            |
  14  // +---------------------------------------------------------------------------+
  15  // |                                                                           |
  16  // | This program is free software; you can redistribute it and/or             |
  17  // | modify it under the terms of the GNU General Public License               |
  18  // | as published by the Free Software Foundation; either version 2            |
  19  // | of the License, or (at your option) any later version.                    |
  20  // |                                                                           |
  21  // | This program is distributed in the hope that it will be useful,           |
  22  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  23  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  24  // | GNU General Public License for more details.                              |
  25  // |                                                                           |
  26  // | You should have received a copy of the GNU General Public License         |
  27  // | along with this program; if not, write to the Free Software Foundation,   |
  28  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  29  // |                                                                           |
  30  // +---------------------------------------------------------------------------+
  31  //
  32  // $Id: lib-database.php,v 1.43 2006/11/12 11:58:00 dhaun Exp $
  33  
  34  /**
  35  * This is the high-level database layer for Geeklog (for the low-level stuff,
  36  * see the system/databases directory).
  37  *
  38  * NOTE: As of Geeklog 1.3.5 you should not have to edit this file any more.
  39  */
  40  
  41  // +---------------------------------------------------------------------------+
  42  // | Table definitions, these are used by the install program to create the    |
  43  // | database schema.  If you don't like the tables names, change them PRIOR   |
  44  // | to running the install after running the install program DO NOT TOUCH     |
  45  // | these. You have been warned!  Also, these variables are used in the core  |
  46  // | Geeklog code                                                              |
  47  // +---------------------------------------------------------------------------+
  48  
  49  $_TABLES['access']              = $_DB_table_prefix . 'access';
  50  $_TABLES['article_images']      = $_DB_table_prefix . 'article_images';
  51  $_TABLES['blocks']              = $_DB_table_prefix . 'blocks';
  52  $_TABLES['commentcodes']        = $_DB_table_prefix . 'commentcodes';
  53  $_TABLES['commentmodes']        = $_DB_table_prefix . 'commentmodes';
  54  $_TABLES['comments']            = $_DB_table_prefix . 'comments';
  55  $_TABLES['cookiecodes']         = $_DB_table_prefix . 'cookiecodes';
  56  $_TABLES['dateformats']         = $_DB_table_prefix . 'dateformats';
  57  $_TABLES['events']              = $_DB_table_prefix . 'events';
  58  $_TABLES['eventsubmission']     = $_DB_table_prefix . 'eventsubmission';
  59  $_TABLES['featurecodes']        = $_DB_table_prefix . 'featurecodes';
  60  $_TABLES['features']            = $_DB_table_prefix . 'features';
  61  $_TABLES['frontpagecodes']      = $_DB_table_prefix . 'frontpagecodes';
  62  $_TABLES['group_assignments']   = $_DB_table_prefix . 'group_assignments';
  63  $_TABLES['groups']              = $_DB_table_prefix . 'groups';
  64  $_TABLES['links']               = $_DB_table_prefix . 'links';
  65  $_TABLES['linksubmission']      = $_DB_table_prefix . 'linksubmission';
  66  $_TABLES['maillist']            = $_DB_table_prefix . 'maillist';
  67  $_TABLES['personal_events']     = $_DB_table_prefix . 'personal_events';
  68  $_TABLES['pingservice']         = $_DB_table_prefix . 'pingservice';
  69  $_TABLES['plugins']             = $_DB_table_prefix . 'plugins';
  70  $_TABLES['pollanswers']         = $_DB_table_prefix . 'pollanswers';
  71  $_TABLES['pollquestions']       = $_DB_table_prefix . 'pollquestions';
  72  $_TABLES['pollvoters']          = $_DB_table_prefix . 'pollvoters';
  73  $_TABLES['postmodes']           = $_DB_table_prefix . 'postmodes';
  74  $_TABLES['sessions']            = $_DB_table_prefix . 'sessions';
  75  $_TABLES['sortcodes']           = $_DB_table_prefix . 'sortcodes';
  76  $_TABLES['speedlimit']          = $_DB_table_prefix . 'speedlimit';
  77  $_TABLES['statuscodes']         = $_DB_table_prefix . 'statuscodes';
  78  $_TABLES['stories']             = $_DB_table_prefix . 'stories';
  79  $_TABLES['storysubmission']     = $_DB_table_prefix . 'storysubmission';
  80  $_TABLES['syndication']         = $_DB_table_prefix . 'syndication';
  81  $_TABLES['topics']              = $_DB_table_prefix . 'topics';
  82  $_TABLES['trackback']           = $_DB_table_prefix . 'trackback';
  83  $_TABLES['trackbackcodes']      = $_DB_table_prefix . 'trackbackcodes';
  84  $_TABLES['tzcodes']             = $_DB_table_prefix . 'tzcodes';
  85  $_TABLES['usercomment']         = $_DB_table_prefix . 'usercomment';
  86  $_TABLES['userindex']           = $_DB_table_prefix . 'userindex';
  87  $_TABLES['userinfo']            = $_DB_table_prefix . 'userinfo';
  88  $_TABLES['userprefs']           = $_DB_table_prefix . 'userprefs';
  89  $_TABLES['users']               = $_DB_table_prefix . 'users';
  90  $_TABLES['vars']                = $_DB_table_prefix . 'vars';
  91  
  92  // the static pages plugin has become an integral part of Geeklog anyway ...
  93  $_TABLES['staticpage']          = $_DB_table_prefix . 'staticpage';
  94  
  95  // ditto for spamx
  96  $_TABLES['spamx']                = $_DB_table_prefix . 'spamx';
  97  
  98  // these tables aren't used by Geeklog any more, but the table names are needed
  99  // when upgrading from old versions
 100  $_TABLES['commentspeedlimit']   = $_DB_table_prefix . 'commentspeedlimit';
 101  $_TABLES['submitspeedlimit']    = $_DB_table_prefix . 'submitspeedlimit';
 102  $_TABLES['userevent']           = $_DB_table_prefix . 'userevent';
 103  
 104  
 105  // +---------------------------------------------------------------------------+
 106  // | DO NOT TOUCH ANYTHING BELOW HERE                                          |
 107  // +---------------------------------------------------------------------------+
 108  
 109  if (strpos ($_SERVER['PHP_SELF'], 'lib-database.php') !== false) {
 110      die ('This file can not be used on its own!');
 111  }
 112  
 113  /**
 114  * Include appropriate DBMS object
 115  *
 116  */
 117  require_once($_CONF['path_system'] . 'databases/'. $_DB_dbms . '.class.php');
 118  
 119  // Instantiate the database object
 120  $_DB = new database($_DB_host, $_DB_name, $_DB_user, $_DB_pass, 'COM_errorLog',
 121                      $_CONF['default_charset']);
 122  
 123  // +---------------------------------------------------------------------------+
 124  // | These are the library functions.  In all cases they turn around and make  |
 125  // | calls to the DBMS specific functions.  These ARE to be used directly in   |
 126  // | the code...do NOT use the $_DB methods directly
 127  // +---------------------------------------------------------------------------+
 128  
 129  /**
 130  * Turns debug mode on for the database library
 131  *
 132  * Setting this to true will cause the database code to print out
 133  * various debug messages.  Setting it to false will supress the
 134  * messages (is false by default). NOTE: Gl developers have put many
 135  * useful debug messages into the mysql implementation of this.  If
 136  * you are using something other than MySQL and if the GL team did
 137  * not write it then you may or may not get something useful by turning
 138  * this on.
 139  *
 140  * @param        boolean     $flag       true or false
 141  *
 142  */
 143  function DB_setdebug($flag)
 144  {
 145      global $_DB;
 146  
 147      $_DB->setVerbose($flag);
 148  }
 149  
 150  /** Setting this on will return the SQL error message. 
 151  * Default is to not display or return the SQL error but
 152  * to record it in the error.log file
 153  *
 154  * @param        boolean     $flag       true or false
 155  */
 156  function DB_displayError($flag)
 157  {
 158      global $_DB;
 159  
 160      $_DB->setDisplayError($flag);
 161  }
 162  
 163  /**
 164  * Executes a query on the db server 
 165  *
 166  * This executes the passed SQL and returns the recordset or errors out
 167  *
 168  * @param    mixed   $sql            String or array of strings of SQL to be executed
 169  * @param    int     $ignore_errors  If 1 this function supresses any error messages
 170  * @return   object  Returns results from query
 171  *
 172  */
 173  function DB_query ($sql, $ignore_errors = 0)
 174  {
 175      global $_DB, $_DB_dbms;
 176  
 177      if (is_array ($sql)) {
 178          if (isset ($sql[$_DB_dbms])) {
 179              $sql = $sql[$_DB_dbms];
 180          } else {
 181              $errmsg = "No SQL request given for DB '$_DB_dbms', only got these:";
 182              foreach ($sql as $db => $request) {
 183                  $errmsg .= LB . $db . ': ' . $request;
 184              }
 185              COM_errorLog ($errmsg);
 186              die ('An SQL error has occurred. Please see error.log for details.');
 187          }
 188      }
 189  
 190      return $_DB->dbQuery ($sql, $ignore_errors);
 191  }
 192  
 193  /**
 194  * Saves information to the database
 195  *
 196  * This will use a REPLACE INTO to save a record into the
 197  * database. NOTE: this function is going to change in the near future
 198  * to remove dependency of REPLACE INTO. Please use DB_query if you can
 199  *
 200  * @param        string      $table          The table to save to
 201  * @param        string      $fields         Comma demlimited list of fields to save
 202  * @param        string      $values         Values to save to the database table
 203  * @param        string      $return_page    URL to send user to when done
 204  *
 205  */
 206  function DB_save($table,$fields,$values,$return_page='') 
 207  {
 208      global $_DB,$_TABLES,$_CONF;
 209  
 210      $_DB->dbSave($table,$fields,$values);
 211  
 212      if (!empty($return_page)) {
 213         print COM_refresh("$return_page");
 214      }
 215  
 216  }
 217  
 218  /**
 219  * Deletes data from the database
 220  *
 221  * This will delete some data from the given table where id = value
 222  *
 223  * @param        string              $table          Table to delete data from
 224  * @param        array|string        $id             field name(s) to use in where clause
 225  * @param        array|string        $value          value(s) to use in where clause
 226  * @param        string              $return_page    page to send user to when done
 227  *
 228  */
 229  function DB_delete($table,$id,$value,$return_page='')
 230  {
 231      global $_DB,$_TABLES,$_CONF;
 232  
 233      $_DB->dbDelete($table,$id,$value);
 234  
 235      if (!empty($return_page)) {
 236          print COM_refresh("$return_page");
 237      }
 238  
 239  }
 240  
 241  /**
 242  * Gets a single item from the database
 243  *
 244  * @param        string      $table      Table to get item from
 245  * @param        string      $what       field name to get
 246  * @param        string      $selection  Where clause to use in SQL
 247  * @return       mixed       Returns value sought
 248  *
 249  */
 250  function DB_getItem($table,$what,$selection='') 
 251  {
 252      if (!empty($selection)) {
 253          $result = DB_query("SELECT $what FROM $table WHERE $selection");
 254      } else {
 255          $result = DB_query("SELECT $what FROM $table");
 256      }
 257      $ITEM = DB_fetchArray($result, true);
 258      return $ITEM[0];
 259  }
 260  
 261  /**
 262  * Changes records in a table
 263  *
 264  * This will change the data in the given table that meet the given criteria and will
 265  * redirect user to another page if told to do so
 266  *
 267  * @param        string          $table              Table to perform change on
 268  * @param        string          $item_to_set        field name to set 
 269  * @param        string          $value_to_set       Value to set abovle field to 
 270  * @param        array|string    $id                 field name(s) to use in where clause 
 271  * @param        array|string    $value              Value(s) to use in where clause
 272  * @param        string          $return_page        page to send user to when done with change
 273  * @param        boolean         $supress_quotes     whether or not to use single quotes in where clause
 274  *
 275  */
 276  function DB_change($table,$item_to_set,$value_to_set,$id='',$value='',$return_page='',$supress_quotes=false) 
 277  {
 278      global $_DB,$_TABLES,$_CONF;
 279  
 280      $_DB->dbChange($table,$item_to_set,$value_to_set,$id,$value,$supress_quotes);
 281  
 282      if (!empty($return_page)) {
 283          print COM_refresh("$return_page");
 284      }
 285  }
 286  
 287  /**
 288  * Count records in a table
 289  *
 290  * This will return the number of records which meet the given criteria in the
 291  * given table.
 292  *
 293  * @param        string              $table      Table to perform count on
 294  * @param        array|string        $id         field name(s) to use in where clause
 295  * @param        array|string        $value      Value(s) to use in where clause
 296  * @return       int     Returns row count from generated SQL
 297  *
 298  */
 299  function DB_count($table,$id='',$value='') 
 300  {
 301      global $_DB;
 302  
 303      return $_DB->dbCount($table,$id,$value);
 304  }
 305  
 306  /**
 307  * Copies a record from one table to another (can be the same table)
 308  *
 309  * This will use a REPLACE INTO...SELECT FROM to copy a record from one table
 310  * to another table.  They can be the same table.
 311  *
 312  * @param        string          $table          Table to insert record into
 313  * @param        string          $fields         Comma delmited list of fields to copy over
 314  * @param        string          $values         Values to store in database field
 315  * @param        string          $tablefrom      Table to get record from
 316  * @param        array|string       $id             Field name(s) to use in where clause 
 317  * @param        array|string    $value          Value(s) to use in where clause
 318  * @param        string          $return_page    Page to send user to when done
 319  *
 320  */
 321  function DB_copy($table,$fields,$values,$tablefrom,$id,$value,$return_page='') 
 322  {
 323      global $_DB,$_TABLES,$_CONF;
 324  
 325      $_DB->dbCopy($table,$fields,$values,$tablefrom,$id,$value);
 326  
 327      if (!empty($return_page)) {
 328          print COM_refresh("$return_page");
 329      }
 330  }
 331  
 332  /**
 333  * Retrieves the number of rows in a recordset
 334  *
 335  * This returns the number of rows in a recordset
 336  *
 337  * @param        object     $recordset      The recordset to operate one
 338  * @return       int         Returns number of rows returned by a previously executed query
 339  *
 340  */
 341  function DB_numRows($recordset)
 342  {
 343      global $_DB;
 344  
 345      return $_DB->dbNumRows($recordset);
 346  }
 347  
 348  /**
 349  * Retrieves the contents of a field
 350  *
 351  * This returns the contents of a field from a result set
 352  *
 353  * @param        object      $recordset      The recordset to operate on
 354  * @param        int         $row            row to get data from
 355  * @param        string      $field          field to return
 356  * @return       (depends on the contents of the field)
 357  *
 358  */
 359  function DB_result($recordset,$row,$field)
 360  {
 361      global $_DB;
 362  
 363      return $_DB->dbResult($recordset,$row,$field);
 364  }
 365  
 366  /**
 367  * Retrieves the number of fields in a recordset
 368  *
 369  * This returns the number of fields in a recordset
 370  *
 371  * @param        object     $recordset       The recordset to operate on
 372  * @return       int         Returns the number fields in a result set
 373  *
 374  */
 375  function DB_numFields($recordset)
 376  {
 377      global $_DB;
 378  
 379      return $_DB->dbNumFields($recordset);
 380  }
 381  
 382  /**
 383  * Retrieves returns the field name for a field
 384  *
 385  * Returns the field name for a given field number
 386  *
 387  * @param        object      $recordset      The recordset to operate on
 388  * @param        int         $fnumber        field number to return the name of
 389  * @return       string      Returns name of specified field
 390  *
 391  */
 392  function DB_fieldName($recordset,$fnumber)
 393  {
 394      global $_DB;
 395  
 396      return $_DB->dbFieldName($recordset,$fnumber);
 397  }
 398  
 399  /**
 400  * Retrieves returns the number of effected rows for last query
 401  *
 402  * Retrieves returns the number of effected rows for last query
 403  *
 404  * @param        object      $recordset      The recordset to operate on
 405  * @return       int         returns numbe of rows affected by previously executed query
 406  *
 407  */
 408  function DB_affectedRows($recordset)
 409  {
 410      global $_DB;
 411  
 412      return $_DB->dbAffectedRows($recordset);
 413  }
 414  
 415  /**
 416  * Retrieves record from a recordset
 417  *
 418  * Gets the next record in a recordset and returns in array
 419  *
 420  * @param        object      $recordset      The recordset to operate on
 421  * @param        boolean     $both           get both assoc and numeric indices
 422  * @return       Array      Returns data for a record in an array
 423  *
 424  */
 425  function DB_fetchArray($recordset, $both = true)
 426  {
 427      global $_DB;
 428  
 429      return $_DB->dbFetchArray($recordset, $both);
 430  }
 431  
 432  /**
 433  * Returns the last ID inserted
 434  *
 435  * Returns the last auto_increment ID generated
 436  *
 437  * @param    resources   $link_identifier    identifier for opened link
 438  * @return   int                             Returns the last ID auto-generated
 439  *
 440  */
 441  function DB_insertId($link_identifier = '')
 442  {
 443      global $_DB;
 444  
 445      return $_DB->dbInsertId($link_identifier);
 446  }
 447  
 448  /**
 449  * returns a database error string
 450  *
 451  * Returns an database error message
 452  *
 453  * @return   string  Returns database error message
 454  *
 455  */
 456  function DB_error()
 457  {
 458      global $_DB;
 459  
 460      return $_DB->dbError();
 461  }
 462  
 463  /**
 464  * Creates database structures for fresh installation
 465  *
 466  * This may not be used by Geeklog currently
 467  *
 468  * @return   boolean     returns true on success otherwise false
 469  *
 470  */
 471  function DB_createDatabaseStructures() 
 472  {
 473      global $_DB;
 474  
 475      return $_DB->dbCreateStructures();
 476  }
 477  
 478  /**
 479  * Executes the sql upgrade script(s)
 480  *
 481  * @param        string      $current_gl_version     version of geeklog to upgrade from
 482  * @return       boolean     returns true on success otherwise false
 483  *
 484  */
 485  function DB_doDatabaseUpgrade($current_gl_version) 
 486  {
 487      global $_DB;
 488  
 489      return $_DB->dbDoDatabaseUpgrade($current_gl_version);
 490  }
 491  
 492  /**
 493  * Lock a table
 494  *
 495  * Locks a table for write operations
 496  *
 497  * @param    string      $table      Table to lock
 498  * @return   void
 499  * @see DB_unlockTable
 500  *
 501  */
 502  function DB_lockTable($table)
 503  {
 504      global $_DB;
 505  
 506      $_DB->dbLockTable($table);
 507  }
 508  
 509  /**
 510  * Unlock a table
 511  *
 512  * Unlocks a table after DB_lockTable
 513  *
 514  * @param    string      $table      Table to unlock
 515  * @return   void
 516  * @see DB_lockTable
 517  *
 518  */
 519  function DB_unlockTable($table)
 520  {
 521      global $_DB;
 522  
 523      $_DB->dbUnlockTable($table);
 524  }
 525  
 526  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics