Page 1 of 1

ODBC and unicode - ??? instead of chinese characters

Posted: Mon Mar 20, 2006 7:52 pm
by tim_kinder
Hello,

I'm trying to develop a web site which uses different languages. A visitor should be able to type his name in his own language, and I'm going to save it to MySQL database.

So I have a php script which reads the form and writes it to MySQL database (I'm using both 3.23.53 and 5.0.15).

Then I can read this from my script, from phpMyAdmin (it may require to set browser encoding to utf-8) and from MySQL Query Browser. Updates are also fine.

But when I'm trying to connect using ODBC driver (3.51) it displays ???? instead of real chinese characters.

I will appreciate any help

Tim Kinder

Posted: Mon Mar 20, 2006 7:56 pm
by feyd
Are you sure the page's content encoding is UTF-8 as well?

Posted: Mon Mar 20, 2006 8:57 pm
by tim_kinder
feyd wrote:Are you sure the page's content encoding is UTF-8 as well?
I think so. First, the script file (php) was saved by Notepad as UTF-8, so it contains FFFE at the very beginning.

I also use

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
And what's the most important for me - both phpMyAdmin and MySQL Query Browser display exactly what I expect from them - as well as my scripts.


This is p1.php :

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

<?php
   	$DB = array( 'host' => 'localhost', 'name' => 'uc', 'username' => 'root', 'password' => '' );

    $DB['link'] = mysql_connect($DB['host'], $DB['username'], $DB['password']);
    mysql_select_db($DB['name']) or die( __FILE__ . "(" . __FILE__ . ")" . " error : " . mysql_error());
    mysql_query('SET NAMES utf8');

	$query = "SELECT * FROM t ORDER BY id DESC LIMIT 0,1;";
	$result = mysql_query( $query );
	$r = mysql_fetch_assoc( $result );
	$t = $r['text'];
	echo "<br><b>Recent record :</b> id={$r['id']} text={$r['text']} <br><br>\n";
	mysql_free_result( $result );
	mysql_close($DB['link']);
	
	
?>	


<form method="post" action="p2.php" enctype="multipart/form-data">
<table>
<td></b>Enter new record :</b></td>
<td>Text</td>
<td><input type="text" name="text" value=""></td>
<td><input type="submit" name="ok" value="ok"><td>
</table>
</form>

</body>
</hrml>
and this is p2.php :

Code: Select all

<?php
	if ( array_key_exists( 'ok', $_REQUEST ) )
	{
		$t = $_REQUEST['text'];

	   	$DB = array( 'host' => 'localhost', 'name' => 'uc', 'username' => 'root', 'password' => '' );
	
	    $DB['link'] = mysql_connect($DB['host'], $DB['username'], $DB['password']);
	    mysql_select_db($DB['name']) or die( __FILE__ . "(" . __FILE__ . ")" . " error : " . mysql_error());
	    mysql_query('SET NAMES utf8');

		$query = "INSERT INTO `t` (`text`) VALUES('{$t}');";
		mysql_query( $query );
		
		mysql_close($DB['link']);
	}
	Header("Location: p1.php");
?>