title: Another database connection in wordpress
body: <p>So part of my layout for my theme needs to query a database other than the database made for wordpress.  I figured I would query the other database like normal.  I wrote a quick function to take care of it:</p>
  
  <pre><code>function my_function() {
    $con = mysql_connect("localhost", "user", "password");
    mysql_select_db("database", $con);
    $result = mysql_query("my query");
    mysql_close($con);
    $all = array();
  
    while ($all[] = mysql_fetch_assoc($result)) {}
    return $all;
  }
  </code></pre>
  
  <p>I'm referencing the function in my header and realized it is breaking the categories in my sidebar.  What's going on?  I closed the connection I thought.  What am I doing wrong?  The error I get for the categories is this:</p>
  
  <p>Warning: mysql_error(): 14 is not a valid MySQL-Link resource in /blog/wp-includes/wp-db.php on line 1098</p>