Hi guys,
I'm trying to modify the plaincart for my needs but I have problem with the cyrillic characters. When I call the data from the database, all I get is ???????.
My database is ok, the collation is utf8_unicode_ci and I can see my characters correctly in phpMyAdmin.
for example here is the index.php:

<?php
require_once 'library/config.php';
require_once 'library/category-functions.php';
require_once 'library/product-functions.php';
require_once 'library/cart-functions.php';

$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];

$catId  = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0;
$pdId   = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0;

require_once 'include/header.php';
?>
<table width="780" border="1" align="center" cellpadding="0" cellspacing="0">
 <tr> 
  <td colspan="3">
  <?php require_once 'include/top.php'; ?>
  </td>
 </tr>
 <tr valign="top"> 
  <td width="150" height="400" id="leftnav"> 
<?php
require_once 'include/leftNav.php';
?>
  </td>
  <td>
<?php
if ($pdId) {
	require_once 'include/productDetail.php';
} else if ($catId) {
	require_once 'include/productList.php';
} else {
	require_once 'include/categoryList.php';
}
?>  
  </td>
  <td width="130" align="center"><?php require_once 'include/miniCart.php'; ?></td>
 </tr>
</table>
<?php
require_once 'include/footer.php';
?>

and the database file:

<?php
require_once 'config.php';

$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

function dbQuery($sql)
{
	$result = mysql_query($sql) or die(mysql_error());
	
	return $result;
}

function dbAffectedRows()
{
	global $dbConn;
	
	return mysql_affected_rows($dbConn);
}

function dbFetchArray($result, $resultType = MYSQL_NUM) {
	return mysql_fetch_array($result, $resultType);
}

function dbFetchAssoc($result)
{
	return mysql_fetch_assoc($result);
}

function dbFetchRow($result) 
{
	return mysql_fetch_row($result);
}

function dbFreeResult($result)
{
	return mysql_free_result($result);
}

function dbNumRows($result)
{
	return mysql_num_rows($result);
}

function dbSelect($dbName)
{
	return mysql_select_db($dbName);
}

function dbInsertId()
{
	return mysql_insert_id();
}
?>

I've tried adding mysql_query('SET NAMES utf8'); after mysql_connect() but it didn't worked.
Any suggestions?
Thanks

Recommended Answers

All 5 Replies

Member Avatar for diafol

Here's something I got recently from a member on DW:

<?php

$link = mysql_connect('...', '...', '...');
if (!$link) {
    die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('...', $link);
if (!$db_selected) {
    die ('Can\'t use ... : '. mysql_error());
}
	mysql_query('SET character_set_results=utf8');
	mysql_query('SET names=utf8');
	mysql_query('SET character_set_client=utf8');
	mysql_query('SET character_set_connection=utf8');
	mysql_query('SET character_set_results=utf8');
	mysql_query('SET collation_connection=utf8_general_ci');
?>

Ensure that your page is encoded as UTF-8 in the head and place all the code above in an include file like db.php. JUst include it in every page that uses mysql. *Should* work. If you can't use encoding in head, use this:

header ('Content-type: text/html; charset=utf-8');

It gives a weird warnings:

Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known.
Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is kn (trying to connect via tcp://...:3306)

and

Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known.

Any suggestions?

Put the correct host of MySql database. Not just one, ( host, username, password ) all must be correct input.

Member Avatar for diafol

Did you use this:

$link = mysql_connect('...', '...', '...');

literally??

Did you put your own hostname, username, password?

//sorry zero13 - simultaneous post

Oops... sorry I've put a wrong password.
But now it WORKS!!!
Thank you, thank you, THANK YOU!!!:-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.