Location: PHPKode > projects > Music and Discography Database > music_db/common_funcs.php
<?
// SQL functions ===============================================
include_once('config.php.inc');

function connectSQL() {
  global $ID,$csign,$db_name,$db_user,$db_pass,$db_host;
  if ($csign==1) return;
  #$ID = mysql_connect($db_host,$db_user,$db_pass);
  #mysql_selectdb($db_name,$ID);
  $ID = mysql_connect("$db_host","$db_user","$db_pass");
  mysql_selectdb("$db_name",$ID);

  mysql_query("SET NAMES 'utf8';",$ID);
  $csign=1;
}
  
function closeSQL() {
  global $ID,$csign;
  if ($csign==1) mysql_close($ID);
  $csign=0;
}
 
function query($qstr) {
  global $ID,$res,$nur;
  $res = mysql_query($qstr, $ID);
  $nur = mysql_num_rows($res);
  #print $qstr.'<BR>';
  #print "--- $nur<BR> ";
}

function sqlcmd($qstr) {
  global $ID,$res,$nur;
  $res = mysql_query($qstr, $ID);
  $nur = mysql_affected_rows();
  #print "$qstr<BR>";
}

function next_row() {
  global $ID,$res;
  $row = mysql_fetch_assoc($res);
  return $row;
}

function select_menu($table,$field,$values) {   # Select menh� k�dezi le adatb�isb� a sorokat.
    global $ID, $res, $nur;
    query("SELECT $field,$values FROM $table GROUP BY $field ORDER BY $field");
    $ff = array(array("*","*"));
    for($i=0;$i<$nur;$i++) {
        $row = mysql_fetch_row($res);
        if($row[0] != '') {
            array_push($ff,$row);
        }
    }
    return $ff;
}

function ifset($variable) {     # teszteli egy v�toz�l�ez��, � ha nem l�ezik, l�rehozza res �t�kel.
    global $$variable;
    if (!isset($$variable)) $$variable = '';
}

function chomp(&$elem) {
  $elem = trim($elem);
  $elem = ltrim($elem);
}

// �tal�os HTML fggv�yek ================================================

// select menut nyomtat el�e defini�t tartalommal
function make_select($content,$name,$selected) {
  global $$content;
  $row = $$content;
  print "<SELECT NAME='$name'>";
  for ($i=0;$i<count($row);$i++) 
  {
    print "<OPTION";
    if ($row[$i]==$selected) print " SELECTED";
    print ">$row[$i]</OPTION>";
  }
  print "</SELECT>";
}

function get_musicans_by_id($id) {
    global $ID, $res, $nur;
    query("SELECT name FROM musicans WHERE musicans_id=$id");
    $row = mysql_fetch_row($res);
    return $row[0];
}
function get_instrument_by_id($id) {
    global $ID, $res, $nur, $instruments_table;
    query("SELECT name FROM $instruments_table WHERE instruments_id=$id");
    $row = mysql_fetch_row($res);
    return $row[0];
}
function get_performer_by_id($id) {
    global $ID, $res, $nur;
    query("SELECT performer FROM album WHERE album_id=$id");
    $row = mysql_fetch_row($res);
    return $row[0];
}

?>
Return current item: Music and Discography Database