title: mysql_real_escape_string method really slow (nearly 1 second)
body: <p>i do have a Query here (PHP with Zend Framework on a MySQL Database) using one POST Parameter as an argument in an SQL Statement.</p>
  
  <p>So i do have a local XAMPP Installation on my development machine and the runtime of this small Script ist something like 150ms no matter if i pass the argument with or without using mysql_real_escape_string() on that argument before.</p>
  
  <p>Then i do have a virtual server with BitNami-WAMP-Stack installed. When i run the Script there (100% same database content) it takes around 260ms without mysql_real_escape_string, this is not as "fast" (i know that 150ms isn't really fast at all) as my local machine but would be okay. But if i do add only one mysql_real_escape_string() to the argument from the POST variable the whole thing takes 1.2 seconds.</p>
  
  <p>And i further noticed that every call to mysql_real_escape_string makes the script run around 1 second slower on the virtual server. On my local machine this does not have any effect.</p>
  
  <p>How can this be? Is this a MySQL Setup thing or a PHP.ini thing or what? Because i do have the 100% same database and PHP source on both machines i guess it can only be parametrization?</p>
  
  <p>Thanks for any help in advance!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>So here is what i do, first connecting the DB (in Bootstrap.php):</p>
  
  <pre><code>$GLOBALS["db"]= new Zend_Db_Adapter_Pdo_Mysql(array(
              'host'     =&gt; "localhost",
              'username' =&gt; "user",
              'password' =&gt; "password",
              'dbname'   =&gt; "database"
              ));
  </code></pre>
  
  <p>And then later in want to query the database:</p>
  
  <pre><code>global $db;
  
  $query = sprintf("SELECT * FROM table WHERE id = '%s'", mysql_real_escape_string($id) );
  
  $db-&gt;query("SET NAMES 'utf8'");
  
  $db-&gt;fetchAll($query);
  </code></pre>
  
  <p>I just made another test: when i add this simple test-line to my code, it makes the script ~600ms slower on the virtual machine:</p>
  
  <pre><code>mysql_real_escape_string("TEST");
  </code></pre>