Welcome to WebmasterWorld Guest from 23.20.241.155

Forum Moderators: open

Message Too Old, No Replies

trying using set names utf 8

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

5+ Year Member



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());
mysql_select_db($dbname);


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)



add:

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)

5+ Year Member



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
<?php
$connection = mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());
mysql_select_db($dbname);
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)

5+ Year Member



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

function parseToXML($htmlStr)
{
$xmlStr=str_replace("","&#241;",$htmlStr);
$xmlStr=str_replace('','i',$xmlStr);
*snip*
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)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member




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)

5+ Year Member



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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
5:29 pm on Apr 19, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month