homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

trying using set names utf 8

 3:53 pm on Apr 17, 2011 (gmt 0)

ive got an issue where i'm using the following query to retrieve info but there are spanish characters in the db

ive set the meta to charset=utf-8"

but i still get the dreaded <?> - i saw somewhere about using set names utf8 in the query when setting up the connection but i cant see where i put it into my actual setup:

this is the query file:

include 'config.php';
include 'opendb.php';

$result = mysql_query("SELECT * FROM jstuff WHERE id=" . $_GET['id'] . " ", $connection) or die("error querying database");

the config:

$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pw';
$dbname = 'name';

and the opendb
$connection = mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());

i'm guessing that the best place to use the set names would be in the opendb.php file but ive no idea of actually how to do this ?

(i'm also assuming this will solve my <?> problem )



 4:02 pm on Apr 17, 2011 (gmt 0)


mysql_query('SET NAMES "UTF-8"');

[edited by: mbabuskov at 4:05 pm (utc) on Apr 17, 2011]


 4:04 pm on Apr 17, 2011 (gmt 0)

BTW, with PHP 5.x you can use the mysql_set_charset() function as well.

Also, if you still have problems, make sure the database is really UTF-8. Spanish characters can be stored in ISO_8859-1 and WIN1252 character sets as well.


 4:33 pm on Apr 17, 2011 (gmt 0)

the db is def utf:
collation is "utf8_general_ci" on the whole db and the column

ive added that in the opendb.php but still no change
$connection = mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());
mysql_query('SET NAMES "UTF-8"');

ive added the live headers addon to FF and get this output

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

i've also added this to an .htaccess file:

AddCharset UTF-8 .php

still getting <?> and cant for the life of me figure this one out...


 4:44 pm on Apr 17, 2011 (gmt 0)

i should also add that ive added a replace function to test it:

function parseToXML($htmlStr)
return $xmlStr;

which doesnt work so obv the character is not being retreived from db correctly in the first place


 5:08 pm on Apr 18, 2011 (gmt 0)

still getting <?> and cant for the life of me figure this one out...

Do you mean when the page is output or are these the actual database values? If it's when the page is output, it may be your document encoding. Make sure your have a valid doctype [webmasterworld.com] and the document encoding is set correctly [webmasterworld.com].


 5:18 pm on Apr 18, 2011 (gmt 0)

its fine in the DB - this is the head

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />


 5:29 pm on Apr 19, 2011 (gmt 0)

Accept charset yes, but what does your server output? Load up Live HTTP Headers in Firefox, see what that says.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved