Title: Database Encoding Issues
Last modified: August 19, 2016

---

# Database Encoding Issues

 *  [darugby](https://wordpress.org/support/users/darugby/)
 * (@darugby)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/database-encoding-issues/)
 * Sorry if this question has been already answered, I searched for a similar thread
   but to no avail.
    I’m currently making a custom theme based on Twenty Ten. My
   main page shows a slideshow with the 5 latest posts of a certain category. To
   do that, I simply used php code to query the wordpress database. So far so good.
   However, the page is in spanish, and I’m having trouble with certain characters
   which aren’t shown properly. Examples are any accented letter (á, é, í, etc.)
   and ñ or Ñ. I suspected an encoding problem: the encoding field in the database
   says utf8_general_ci … I tried changing the charset in the meta tag in the header
   but nothing. Then it hit me: WordPress uses the same database and has no problem
   with said characters (the posts are displayed fine, the problem arises when I
   query the database and try to print any field)! So my question is: how does wordpress
   handle these special characters, and how can I mimic this “handling” so they 
   are properly shown?
 * Here is an code example:
 *     ```
       <?php
       $link = mysql_connect("localhost", "my_db_name","my_password");
       mysql_select_db("darugby_wpress", $link);
       $sql = " SELECT p.post_title as title, p.guid as hlink, p.post_date as pdate, p.post_content as content\n"
           . "FROM wp_posts as p INNER JOIN wp_term_relationships as l ON p.ID = l.object_id\n"
           . "WHERE p.post_type = \"post\" AND (l.term_taxonomy_id = 1 OR l.term_taxonomy_id = 4 )\n"
           . "ORDER BY pdate Desc LIMIT 0, 5 ";
       $result = mysql_query($sql);
       while ($row = mysql_fetch_array($result)){
   
       echo $row["title"];
   
       }
       ?>
       ```
   
 * The output of this code will show the last titles corresponding to categories
   1 or 4, however any of the problematic characters will be shown wrong.
 * Thanks in advance!

The topic ‘Database Encoding Issues’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [encoding](https://wordpress.org/support/topic-tag/encoding/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [darugby](https://wordpress.org/support/users/darugby/)
 * Last activity: [15 years, 4 months ago](https://wordpress.org/support/topic/database-encoding-issues/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
