<?php

$GLOBALS['dbhost'] = '1.2.3.4';
$GLOBALS['dbuser'] = 'testuser';
$GLOBALS['dbpass'] = 'testpass';
$GLOBALS['dbname'] = 'testdb';

function getconn() {
  $conn = mysql_connect($GLOBALS['dbhost'], $GLOBALS['dbuser'], $GLOBALS['dbpass']);
  if ($conn) {
    mysql_select_db($GLOBALS['dbname'], $conn);
  } else {
    print "connection failed\n";
  }

  return $conn;
}

function testquery($conn) {
  $res = mysql_query("select * from test_table limit 1", $conn);
  if ($res) {
    $row = mysql_fetch_row($res);
    if ($row) {
      print "got initial row\n";
    } else {
      print "row fetch failed\n";
    }
  } else {
    print "query failed\n";
  }
}

$conn = getconn();
testquery($conn);
sleep(15);
testquery($conn);

testquery(getconn());
