<?php	// TWIG	MySQL Functions

 Function SQLString ($string) {		// Fix SQL Strings
  $string = addslashes($string);
  return $string;
 }

 Function MakeInsertString ($data) {
  while ( list( $key, $val ) = each( $data ) ) {
   if ($key && $val) {
    $string["fields"] .= "$key, ";
    $string["values"] .= "'" . SQLString($val) . "', ";
   }
  }
  $string["fields"]=ereg_replace(", $","",$string["fields"]);
  $string["values"]=ereg_replace(", $","",$string["values"]);
  return $string;
 }

 Function MakeUpdateString ($data) {
  while ( list($key,$val) = each($data) ) {
   if ($data["$key"]) {
    $strings .= $key . " = '" . SQLString($val) . "', ";
   }
  }
  $strings=ereg_replace(", $", " ", $strings);
  return $strings;
 }

 Function dbQuery ($statement) {
  global $dbconfig;
  mysql_pconnect($dbconfig["sqlserver"],$dbconfig["sqlusername"],$dbconfig["sqlpassword"]);
  mysql_select_db($dbconfig["defaultdb"]);
  $result=@mysql_query($statement);
  if (mysql_error()) {
   PrintError(mysql_error());
  }
  else { return $result; }
  return $result;
 }

// mysql_result shouldnt be mixed with fetch_row or fetch_object or fetch_array
// PDK 2/11/99
 Function dbResult ($result,$i,$field) {
  return mysql_result($result,$i,$field);
 }

 Function dbNumRows ($result) {
  return mysql_numrows($result);
 }

 Function dbResultArray ($result,$i) {
  @mysql_data_seek($result,$i);
  return mysql_fetch_array($result);
 }

?>
