title: Getting a mysql-link resource error - but on the same successful link resource used just before
body: <p>I have this code:</p>
  
  <pre><code>public function delete($messageID) {
      if (is_array($this-&gt;sentArr)) {
          foreach ($this-&gt;sentArr as $key =&gt; $value) {
              $implodeData[$key] = $this-&gt;sentArr[$key]-&gt;messageID;
              if ($this-&gt;sentArr[$key]-&gt;messageID == $messageID) {
                  unset($this-&gt;sentArr[$key]);
                  }
              }
          $implodedSent = implode(',', $implodeData);
          $result = $this-&gt;_database-&gt;updatePMUser('sentArr', $implodedSent, 'UID', $this-&gt;UID);
          }
  </code></pre>
  
  <p>Which is just a code to delete a message in a private message mailbox-like script.  Before this section of the script fires, I use $this->_database-> many times to pull the names of the messages, etc - that all works fine, but when I click the delete button and it processes the request and sends me to the function above, I get the following error:</p>
  
  <pre><code>Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user '*private*'@'localhost' (using password: NO) in /var/www/html/evoHTDOCS/tinUser_database.php on line 25
  
  Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /var/www/html/evoHTDOCS/tinUser_database.php on line 25
  
  Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/html/evoHTDOCS/tinUser_database.php on line 210
  Access denied for user '*private*'@'localhost' (using password: NO)ERROR2
  </code></pre>
  
  <p>Disregard the "ERROR2" at the end, that's just the catch for a non-result and it tells me which part of the script went wrong.  Anyway - I use the same link-resource ($this->connection) many times in this same instance of this same class without error - but for some reason this one brings up that error.  Also, what's odd to me is that in the error messages the username is different than the username that I am using to login (they are constants defined in a config file) - it's using the primary username instead of mine and yes, I checked the permissions and they are all set (and again, it links just fine with the same information many times before this function.)  It sounds like all the sudden it says it can't connect to the database it should already be connected to.</p>
  
  <p>If you need it, here is the database section that starts the link and then the function that is causing the error:</p>
  
  <pre><code>public function __construct() {
      $this-&gt;connection = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
      mysql_select_db(DB_NAME, $this-&gt;connection) or die(mysql_error());
  
  public function updatePMUser($field, $data, $whereField, $whereData) {
      $data = $this-&gt;escapeString($data);
      $query = "UPDATE ".PM_USERS_TABLE." SET ".$field." = '$data' WHERE ".$whereField." = '$whereData'";
      $result = mysql_query($query, $this-&gt;connection);
      if ($result)
          return $result;
      else {
          echo mysql_error();
          die("ERROR2");
          }
      }
  </code></pre>
  
  <p>It's all still in production so yes there is some trimming to do, but what could be causing the exact same connection to suddenly fail at a specific function?  I've checked and rechecked spelling and all that.  Thanks for any help.</p>