title: mysql_real_escape_string and PDO no connection in mvc pattern
body: <p>I have created my own mvc pattern based on the codeigniter framework style. My problem now is that i want to prevent from SQL injection, and for that purpose i would like to use mysql_real_escape_string(). But for when i use it, it keeps erroring since it apparently don't have a the "link/source" to the database?</p>
  
  <p>I get the php error:</p>
  
  <blockquote>
    <p>Warning: mysql_real_escape_string(): Can't connect to local MySQL
    server through socket '/var/lib/mysql/mysql.sock' (2) in
    /hsphere/local/home/../dev/simple_blog/models/users_model.php on line
    8</p>
    
    <p>Warning: mysql_real_escape_string(): A link to the server could not be
    established in
    /hsphere/local/home/../dev/simple_blog/models/users_model.php on line
    8</p>
  </blockquote>
  
  <p>I don't quite understand why though, since i can get stuff in and out of my DB but for some reason i can't protect it???</p>
  
  <p>Here is my function giving the error</p>
  
  <pre><code>public function getUserByName($username){
      $username = mysql_real_escape_string($username);
      $sql = "SELECT * FROM ".$this-&gt;db_table." WHERE username='".$username."' LIMIT 1";
      $q = $this-&gt;db-&gt;query($sql);
  
      if($q-&gt;rowCount() &gt; 0){
        foreach($q-&gt;fetch() as $key =&gt; $row){
          $data[$key] = $row;
        }
        return $data;
      }
    }
  </code></pre>
  
  <p>As you can see I use mysql_real_escape_string() at the top, and then later on, do query stuff. Anyone know why this don't work and if yes, how would i fix it?</p>
  
  <p>NOTE: Im not a shark to PDO, and $this->db is the PDO class.</p>