Location: PHPKode > projects > MercuryBoard > MercuryBoard/databases/mysql.php
<?php
/*
MySQL Module for MercuryBoard
*/

function connect_db($db_host, $db_user, $db_pass, $db_name){
  $connection = @mysql_connect($db_host, $db_user, $db_pass);
  @mysql_select_db($db_name);
  return $connection;
}

function debugquery($query){
  global $query_log, $querytime, $fulldebug;

  $query_log .= "$query<br>\n";

  if(substr(trim(strtoupper($query)), 0, 6) != "SELECT"){
    return false;
  }

  $mtime     = split(" ", microtime());
  $starttime = $mtime[1] + $mtime[0];

  $quer = mysql_query("EXPLAIN $query");

  $mtime     = split(" ", microtime());
  $endtime   = $mtime[1]  + $mtime[0];
  $totaltime = $endtime   - $starttime;
  $querytime = $querytime + $totaltime;

  $fulldebug .= "
  <br><br><pre><b>Query</b>: $query<br><b>Query Execution Time</b>: $totaltime
  <table border='1' width='80%' cellpadding='3' cellspacing='0'>
    <tr>
      <td><b>table</b></td>
      <td><b>possible_keys</b></td>
      <td><b>key</b></td>
      <td><b>rows</b></td>
      <td><b>extra</b></td>
    </tr>\n";

  while($d = mysql_fetch_array($quer)){
    $fulldebug .= "
    <tr>
      <td>{$d['table']}&nbsp;</td>
      <td>{$d['possible_keys']}&nbsp;</td>
      <td>{$d['key']}&nbsp;</td>
      <td>{$d['rows']}&nbsp;</td>
      <td>{$d['Extra']}&nbsp;</td>
    </tr>\n";
  }

  $fulldebug .= "</table></pre>";

  return true;
}

function query($query){
  global $debug, $querycount;

  $querycount++;

  if(isset($debug)){
    debugquery($query);
  }

  return mysql_query($query);
}

function fetch($query){
  global $debug, $querycount;

  $querycount++;

  if(isset($debug)){
    debugquery($query);
  }

  $fetch = mysql_query($query);
  return mysql_fetch_array($fetch);
}

function nqfetch($query){
  return mysql_fetch_array($query);
}

function num_rows($query){
  return mysql_num_rows($query);
}

function aff_rows(){
  return mysql_affected_rows();
}
?>
Return current item: MercuryBoard