Location: PHPKode > projects > phpMyDesigner > pmd_get_info.php
<?php
/*
@author  Ivan A Kirillov (hide@address.com)
www.phpMyDesigner.net
*/
require_once './libraries/relation.lib.php';
function get_tabs() // PMA_DBI
{
  global $db;
  $GLOBALS['PMD']['TABLE_NAME'] = array();// that foreach no error
  $GLOBALS['PMD']['OWNER'] = array(); 
  $GLOBALS['PMD']['TABLE_NAME_SMALL'] = array(); 
  PMA_DBI_select_db($db);
  $alltab_rs  = PMA_DBI_query('SHOW TABLES FROM '.PMA_backquote($db), NULL, PMA_DBI_QUERY_STORE);
  $i=0;
  while ($val = @PMA_DBI_fetch_row($alltab_rs)) 
  {
    $GLOBALS['PMD']['TABLE_NAME'][$i] = $db.".".$val[0];
    $GLOBALS['PMD']['OWNER'][$i] = $db;
    $GLOBALS['PMD']['TABLE_NAME_SMALL'][$i] = $val[0];  
    // TYPE TABLE
    $table_info_result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($GLOBALS['PMD']['TABLE_NAME_SMALL'][$i], true) . '\';', NULL, PMA_DBI_QUERY_STORE);
    $showtable         = PMA_DBI_fetch_assoc($table_info_result);
    PMA_DBI_free_result($table_info_result);
    unset( $table_info_result );
    $GLOBALS['PMD']['TABLE_TYPE'][$i] = strtoupper($showtable['Type']);
    $i++;
  } 
//  return $GLOBALS['PMD'];       // many bases // not use ??????
}

function get_tab_info() // PMA_DBI //PMA_backquote
{ 
  global $db;
  PMA_DBI_select_db($db);
  $tab_column = array();
  for ( $i=0; $i < sizeof( $GLOBALS['PMD']["TABLE_NAME"] ); $i++ ) 
  {
    PMA_DBI_select_db($db);
    $fields_rs   = PMA_DBI_query('SHOW FULL FIELDS FROM '.PMA_backquote($GLOBALS['PMD']["TABLE_NAME_SMALL"][$i]), NULL, PMA_DBI_QUERY_STORE);
    $fields_cnt  = PMA_DBI_num_rows($fields_rs);
    $j=0;
    while ($row = PMA_DBI_fetch_assoc($fields_rs)) 
    {   
      $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_ID'][$j]   = $j;
      $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_NAME'][$j] = $row['Field'];
      $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['TYPE'][$j]        = $row['Type'];
      $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['NULLABLE'][$j]    = $row['Null'];
      $j++;
    }
  }
  return $tab_column;
}
//-------------------------------------CONTR-----------------------------------------------
function get_script_contr()
{
  global $db;
  PMA_DBI_select_db($db);
  $con["C_NAME"] = array();
  PMA_getRelationsParam();
  $i=0;
  $alltab_rs  = PMA_DBI_query('SHOW TABLES FROM '.PMA_backquote($db), NULL, PMA_DBI_QUERY_STORE);
  while ($val = @PMA_DBI_fetch_row($alltab_rs)) 
  {
    $row = PMA_getForeigners($db,$val[0],'','internal');
    if($row!==false)
      foreach($row as $field => $value)
      { 
        $con['C_NAME'][$i] = '';
        $con['DTN'][$i]    = $db.".".$val[0];
        $con['DCN'][$i]    = $field;
        $con['STN'][$i]    = $value['foreign_db'].".".$value['foreign_table'];
        $con['SCN'][$i]    = $value['foreign_field'];
        $i++;
      }
    $row = PMA_getForeigners($db,$val[0],'','innodb');
    if($row!==false)
      foreach($row as $field => $value)
      { 
        $con['C_NAME'][$i] = '';
        $con['DTN'][$i]    = $db.".".$val[0];
        $con['DCN'][$i]    = $field;
        $con['STN'][$i]    = $value['foreign_db'].".".$value['foreign_table'];
        $con['SCN'][$i]    = $value['foreign_field'];
        $i++;
      }
  } 
  
  $ti=0;
  $script_contr = "<script> var contr = new Array();";
  for ( $i=0; $i < sizeof( $con["C_NAME"] ); $i++ ) 
  {
    $script_contr .= " contr[$ti] = new Array();\n";
    $script_contr .= "  contr[$ti]['".$con['C_NAME'][$i]."'] = new Array();\n";
    if(in_array($con['DTN'][$i],$GLOBALS['PMD']["TABLE_NAME"]) && in_array($con['STN'][$i],$GLOBALS['PMD']["TABLE_NAME"])) //    set_tables.php
    {
      $script_contr .= "  contr[$ti]['".$con['C_NAME'][$i]."']['".$con['DTN'][$i]."'] = new Array();\n";$m_col = array();//}
      $script_contr .= "  contr[$ti]['".$con['C_NAME'][$i]."']['".$con['DTN'][$i]."']['".$con['DCN'][$i]."'] = new Array();\n";//}
      $script_contr .= "    contr[$ti]['".$con['C_NAME'][$i]."']['".$con['DTN'][$i]."']['".$con['DCN'][$i]."'][0] = '".$con['STN'][$i]."';\n"; // 
      $script_contr .= "    contr[$ti]['".$con['C_NAME'][$i]."']['".$con['DTN'][$i]."']['".$con['DCN'][$i]."'][1] = '".$con['SCN'][$i]."';\n"; // 
    }
    $ti++;
  }
  $script_contr .= "</script>";
  return $script_contr;
}

function get_p_k_contr()
{
  global $db;
  PMA_DBI_select_db($db);
  //$tabs = get_tabs();
  $tab_pk = array();
  $owners = get_owners(); 
  $script_contr = "<script> var contr = new Array();";
  
  for($I=0;$I<sizeof($GLOBALS['PMD']['TABLE_NAME_SMALL']);$I++)
  {
    $stmt = PMA_DBI_query("SHOW CREATE TABLE ".PMA_backquote($GLOBALS['PMD']['TABLE_NAME_SMALL'][$I]));
    while ($create_table = PMA_DBI_fetch_array($stmt)) 
    {
      preg_match_all ("/PRIMARY KEY\s*\(([\w`,\s]+)\)/im", $create_table[1], $m);
      if(isset($m[1][0]))
      {
        preg_match_all ("/[`,\s]*(\w+)[`,\s]*/im", $m[1][0], $k); // FK
        foreach($k[1] as $key => $value)
        $tab_pk[$GLOBALS['PMD']['OWNER'][$I].'.'.$GLOBALS['PMD']['TABLE_NAME_SMALL'][$I].'.'.$value]=1; // 1 - in oracle name contrains
      }
    }
  }
return $tab_pk;
}

function get_script_tabs()
{
  $script_tabs = "<script> var j_tabs = new Array();\n";
  for ( $i=0; $i < sizeof( $GLOBALS['PMD']['TABLE_NAME'] ); $i++ ) 
    $script_tabs .= "j_tabs['".$GLOBALS['PMD']['TABLE_NAME'][$i]."'] = '".$GLOBALS['PMD']['TABLE_TYPE'][$i]."';\n";
  $script_tabs .= "</script>";
  return $script_tabs;
}

function get_tab_pos()
{ 
  PMA_getRelationsParam();
  $stmt = PMA_query_as_cu("SELECT * FROM ".PMA_backquote($GLOBALS['PMD']['TABLE_NAME_POS']), FALSE, PMA_DBI_QUERY_STORE); 
  if( $stmt ) // exist table repository
  {
    while($t_p = PMA_DBI_fetch_array($stmt, MYSQL_ASSOC))
    { 
      $t_name = $t_p['DB_NAME'].'.'.$t_p['TABLE_NAME'];
      $tab_pos[ $t_name ]['X'] = $t_p['X'];
      $tab_pos[ $t_name ]['Y'] = $t_p['Y'];
      $tab_pos[ $t_name ]['V'] = $t_p['V'];
      $tab_pos[ $t_name ]['H'] = $t_p['H'];
    }
  } 
  return isset($tab_pos)?$tab_pos:NULL;
}

function get_owners() 
{
  $m = array();
  $j=0;
  for ( $i=0; $i < sizeof( $GLOBALS['PMD']["OWNER"] ); $i++ ) 
    if(!in_array($GLOBALS['PMD']["OWNER"][$i],$m)) $m[$j++] = $GLOBALS['PMD']["OWNER"][$i];
  return $m;
}

?>
Return current item: phpMyDesigner