title: Function won't accept less than three arguments
body: <p>I'm working with someone else's database connection PHP function that works fine as long as I pass it at least three arguments.  If I pass it two argument, then the apache log says:</p>
  
  <p><code>mysql_real_escape_string() expects parameter 2 to be resource, null given</code></p>
  
  <p>I need the function to take a SQL query like so:</p>
  
  <p><code>$sql = DatabaseManager::prepare("SELECT * FROM sometable WHERE somevar = %d", $var);</code> </p>
  
  <p>and prepare it for safe execution.  Can someone help make it accept two arguments?</p>
  
  <pre><code>public static function prepare($query = null) { // ( $query, *$args )
  
      $args = func_get_args();
  
      array_shift($args);
  
      // If args were passed as an array (as in vsprintf), move them up
      if ( isset($args[0]) &amp;&amp; is_array($args[0]) ){
          $args = $args[0];
      }
  
      $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it
      $query = str_replace('"%s"', '%s', $query); // doublequote unquoting
      $query = str_replace('%s', "'%s'", $query); // quote the strings
  
      for($i=0; $i&lt;count($args); $i++){
          $args[$i] = mysql_real_escape_string($args[$i], self::$currentCon);
      }
  
      //array_walk($args, array(&amp;$this, 'mysql_real_escape_string'));
  
      return @vsprintf($query, $args);
  }   
  </code></pre>
  
  <p>Thanks a ton!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As deceze points out, this is about <code>self::$currentCon)</code> and means that a database connection is coming back <code>null</code></p>
  
  <p>I've tried this multiple times.  Still curious about why this works:</p>
  
  <pre><code>$sql = DatabaseManager::prepare("SELECT * FROM sometable WHERE id = ".$somevar); 
  </code></pre>
  
  <p>but this fails:</p>
  
  <pre><code>$sql = DatabaseManager::prepare("SELECT * FROM sometable WHERE somevar = %d", $var); 
  </code></pre>
  
  <p>How would that affect <code>self::$currentCon)</code>?</p>