title: mysql_connect doesn't work second time
body: <p>duplicate of unanswered: <a href="https://stackoverflow.com/q/26174159/3338098">How to reconnect in php adodb after exceptions: Mysql server gone away or Lost connection to MySQL server during query</a></p>
  
  <p>mysql_connect works the first time, but never works after that...</p>
  
  <pre><code>$connectDb = mysql_connect(secret, secret, secret);
  mysql_select_db("secret", $connectDb);
  
  $sleepPeriod = 1800;
  sleep($sleepPeriod);
  while (true) {
    $result = mysql_query("good query", $connectDb);
    if (!$result) {
      if (mysql_error()=='MySQL server has gone away') {
        echo "MySql connection was disconnected... reconecting...\n";
        $connectDb = mysql_connect(secret, secret, secret);
        mysql_select_db("secret", $connectDb);
        continue;
      } else {
        die("Invalid Query: ".__FILE__.':'.__LINE__.' '.mysql_error()."\n");
      }
    }
    //DO STUFF
    sleep($sleepPeriod);
  }
  </code></pre>
  
  <p>if a timeout or disconnect happens <code>mysql_connect</code> seems to fail and <code>mysql_error</code> continually returns <code>"MySQL server has gone away"</code>, which results in an infinite loop that can go for days.  is there some other way to clear the error response of <code>mysql_error</code> or to make <code>mysql_connect</code> run a second time without having to restart this program manually or resorting to cron.</p>
  
  <p>I just noticed that <code>mysql_connect</code> has a strange(stupid?) parameter called <code>new_link</code>, however it would be an outrageous design if php's mysql code purposefully disables reconnects on timeout by default... I'll test regardless and get back.</p>