PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 17th, 2004, 04:25 PM
blockcipher blockcipher is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2003
Posts: 701 blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 40 m 21 sec
Reputation Power: 55
PHP5/MySQL/UTF8

Hello,

I'm trying to get PHP 5.0.1 and MySQL 4.1.4gamma working together to display UTF-8 encoded text. Using ColdFusion, this worked without any problems, however I can't seem to get PHP to output the text correctly.

Here is my current code:

PHP Code:
<?php
header
("Content-Type: text/html; charset=utf-8");

mb_http_output('UTF-8');

ob_start('mb_output_handler');
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body style="font-family=Arial">

<?php

    $connection 
mysqli_connect('server','root','');

    
$sql 'SELECT * FROM unicode_test.unicode_text';

    
$stmt mysqli_prepare($connection$sql);

    
mysqli_stmt_execute($stmt);
    
mysqli_stmt_store_result($stmt);
    
mysqli_bind_result($stmt$id$value);

    while (
mysqli_fetch($stmt))
    {
        print 
"$id -- $value<br/>";
    }

    
mysqli_close($connection);

?>

</body>
</html>

<?php ob_end_flush(); ?>


I think my database is set up correctly, so I think I'm goofing something up in my PHP. Any suggestions?

Oh, and yes, my code probably isn't the best but I haven't touched PHP in quite a while.
__________________
blockcipher
---------------
Gratuitously stolen...
mysql> SELECT * FROM user WHERE clue > 0;
0 Results Returned.

PHP5/MySQL/UTF-8
My Tech Blog

Last edited by blockcipher : April 15th, 2005 at 10:19 AM.

Reply With Quote
  #2  
Old September 17th, 2004, 05:06 PM
blockcipher blockcipher is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2003
Posts: 701 blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 40 m 21 sec
Reputation Power: 55
O.K. I think I'm a bit further in my debugging. It turns out that the client character set is latin1_swedish_ci. Does anyone know how to change that for mysqli?

Reply With Quote
  #3  
Old September 20th, 2004, 10:48 AM
blockcipher blockcipher is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2003
Posts: 701 blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 40 m 21 sec
Reputation Power: 55
Nevermind, I found it. You have to use the mysql_options command to point the mysql client to a valid my.cnf or my.ini file.

Here's my example code:

PHP Code:
<?php
header
("Content-Type: text/html; charset=utf-8");
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body style="font-family=Arial">

<?php

    $dbobject 
mysqli_init();

    
$dbobject->options(MYSQLI_READ_DEFAULT_FILE"c:\winnt\my.ini");

    
$dbobject->real_connect('server''username''password''unicode_test');

    
$charset $dbobject->character_set_name();

    print 
"Charset = $charset<br/>";

    
$sql 'SELECT * FROM unicode_test.unicode_text';

    
$result $dbobject->query($sql);

    while (
$row $result->fetch_assoc())
    {
        
printf("%d -- %s<br/>"$row['id'], $row['value']);
    }

    
$dbobject->close();

?>

</body>
</html>

Reply With Quote
  #4  
Old May 27th, 2005, 06:32 PM
hayato1 hayato1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 31 hayato1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 32 sec
Reputation Power: 5
I'm also trying but no luck at all
your topic wrote php,mysql,/utf-8

but is mysqli mysql?
I'm using mysql, apache , php also trying to get it works
and that should be someway for it to work without changing more setting in .ini, .conf and so on because it can be view perfectly in latest phpmyadmin and not a normal website with header as utf-8

i tried looking into alot forums and alot web result this question/ problem didn't have a answer or i just have rotten luck.

Reply With Quote
  #5  
Old June 14th, 2005, 10:20 AM
blockcipher blockcipher is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2003
Posts: 701 blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level)blockcipher User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 40 m 21 sec
Reputation Power: 55
Sorry for the late response, but I don't frequent the PHP forums very often.

mysqli is the new mysql extension for PHP 5. It supports unicode, the new authentication protocol, prepared statements, and other features.

I don't know how phpMyAdmin managed to make stuff work without doing what I stated. Sorry.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5/MySQL/UTF8


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT