title: Whats does pg_escape_string exactly do?
body: <p>I'm using the following script which takes the data from a html form and stores in a Postgres DB. There is this pg_escape_string function which stores the value from the form to the php variable. Searching the web throughout, I found that pg_escape_string escapes a string for insertion into the database. I'm not much clear on this. What does it actually escaping? What actually happens when its said that a string is escaped?</p>
  
  <pre><code>&lt;html&gt;
     &lt;head&gt;&lt;/head&gt;
     &lt;body&gt;       
  
   &lt;?php
   if ($_POST['submit']) {
       // attempt a connection
       $dbh = pg_connect("host=localhost dbname=test user=postgres");
       if (!$dbh) {
           die("Error in connection: " . pg_last_error());
       }
  
       // escape strings in input data
       $code = pg_escape_string($_POST['ccode']);
       $name = pg_escape_string($_POST['cname']);
  
       // execute query
       $sql = "INSERT INTO Countries (CountryID, CountryName) VALUES('$code', '$name')";
       $result = pg_query($dbh, $sql);
       if (!$result) {
           die("Error in SQL query: " . pg_last_error());
       }
  
       echo "Data successfully inserted!";
  
       // free memory
       pg_free_result($result);
  
       // close connection
       pg_close($dbh);
   }
   ?&gt;       
  
      &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
        Country code: &lt;br&gt; &lt;input type="text" name="ccode" size="2"&gt;  
        &lt;p&gt;
        Country name: &lt;br&gt; &lt;input type="text" name="cname"&gt;       
        &lt;p&gt;
        &lt;input type="submit" name="submit"&gt;
      &lt;/form&gt; 
  
     &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>