title: Update a specific column value using a php snippet in wordpress
body: <p>I want to retrieve the distinct post_title values from the wp_posts table and then to update the post_name column with the urlencoded post_title values.</p>
  
  <p>I tried the following php code:</p>
  
  <pre><code>&lt;?php
          global $wpdb;
          $result = $wpdb-&gt;get_results ( "SELECT * FROM wp_posts" );
          foreach ( $result as $wpposts )   {
              $wp_temp = $wpposts-&gt;post_title;
          $wp_title = urlencode($wp_temp);
            mysql_query("UPDATE wp_posts SET post_name = '" . $wp_title . "'  WHERE post_title != NULL") or die(mysql_error());  
              }
        ?&gt;
  </code></pre>
  
  <p>However, I got the following error message:</p>
  
  <blockquote>
    <p>Warning: mysql_query(): Can't connect to local MySQL server through
    socket '/var/run/mysqld/mysqld.sock' (2) in
    /hermes/xxxxxxxxxxx/b1890/.../page-temp.php on line 19 Warning:
    mysql_query(): A link to the server could not be established in
    /hermes/xxxxxxxxxxx/b1890/.../page-temp.php
    on line 19 Can't connect to local MySQL server through socket
    '/var/run/mysqld/mysqld.sock' (2)</p>
  </blockquote>
  
  <p>How can I make it done?
  In addition, is there a way to select only distinct post_tile rows only?</p>
  
  <p>Thanks.</p>