home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / get_foreign.lib.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  3.4 KB  |  84 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  *
  5.  * @version $Id: get_foreign.lib.php 11326 2008-06-17 21:32:48Z lem9 $
  6.  */
  7. if (! defined('PHPMYADMIN')) {
  8.     exit;
  9. }
  10.  
  11. /**
  12.  *
  13.  */
  14. require_once './libraries/Table.class.php';
  15.  
  16. /**
  17.  * Gets foreign keys in preparation for a drop-down selector
  18.  * Thanks to <markus@noga.de>
  19.  */
  20.  
  21.  
  22. // lem9: we always show the foreign field in the drop-down; if a display
  23. // field is defined, we show it besides the foreign field
  24. $foreign_link = false;
  25. if ($foreigners && isset($foreigners[$field])) {
  26.     $foreigner       = $foreigners[$field];
  27.     $foreign_db      = $foreigner['foreign_db'];
  28.     $foreign_table   = $foreigner['foreign_table'];
  29.     $foreign_field   = $foreigner['foreign_field'];
  30.  
  31.     // Count number of rows in the foreign table. Currently we do
  32.     // not use a drop-down if more than 200 rows in the foreign table,
  33.     // for speed reasons and because we need a better interface for this.
  34.     //
  35.     // We could also do the SELECT anyway, with a LIMIT, and ensure that
  36.     // the current value of the field is one of the choices.
  37.  
  38.     $the_total   = PMA_Table::countRecords($foreign_db, $foreign_table, TRUE);
  39.  
  40.     if ((isset($override_total) && $override_total == true) || $the_total < $cfg['ForeignKeyMaxLimit']) {
  41.         // foreign_display can be FALSE if no display field defined:
  42.         $foreign_display = PMA_getDisplayField($foreign_db, $foreign_table);
  43.  
  44.         $f_query_main = 'SELECT ' . PMA_backquote($foreign_field)
  45.                         . (($foreign_display == FALSE) ? '' : ', ' . PMA_backquote($foreign_display));
  46.         $f_query_from = ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table);
  47.         $f_query_filter = empty($foreign_filter) ? '' : ' WHERE ' . PMA_backquote($foreign_field)
  48.                             . ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"'
  49.                             . (($foreign_display == FALSE) ? '' : ' OR ' . PMA_backquote($foreign_display)
  50.                                 . ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"'
  51.                                 );
  52.         $f_query_order = ($foreign_display == FALSE) ? '' :' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display);
  53.         $f_query_limit = isset($foreign_limit) ? $foreign_limit : '';
  54.  
  55.         if (!empty($foreign_filter)) {
  56.             $res = PMA_DBI_query('SELECT COUNT(*)' . $f_query_from . $f_query_filter);
  57.             if ($res) {
  58.                 $the_total = PMA_DBI_fetch_value($res);
  59.                 @PMA_DBI_free_result($res);
  60.             } else {
  61.                 $the_total = 0;
  62.             }
  63.         }
  64.  
  65.         $disp            = PMA_DBI_query($f_query_main . $f_query_from . $f_query_filter . $f_query_order . $f_query_limit);
  66.         if ($disp && PMA_DBI_num_rows($disp) > 0) {
  67.             // garvin: If a resultset has been created, pre-cache it in the $disp_row array
  68.             // This helps us from not needing to use mysql_data_seek by accessing a pre-cached
  69.             // PHP array. Usually those resultsets are not that big, so a performance hit should
  70.             // not be expected.
  71.             $disp_row = array();
  72.             while ($single_disp_row = @PMA_DBI_fetch_assoc($disp)) {
  73.                 $disp_row[] = $single_disp_row;
  74.             }
  75.             @PMA_DBI_free_result($disp);
  76.         }
  77.     } else {
  78.         unset($disp_row);
  79.         $foreign_link = true;
  80.     }
  81. }  // end if $foreigners
  82.  
  83. ?>
  84.