473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with Writing Unicode into MySQL via PHP

Hello All,

I am trying to fix PHP code developed by somebody else and my
knowledge of PHP is very limited so I'd appreciate any help.

I have a MySQL database configured to accept UTF-8 in all fields.

When I update the database with Unicode via phpMyAdmin web interface I
am able to write and save unicode values in all fields.

However when i try to update the database via web I am not
successful.

For example, if I enter "čćđšž" into the field I amupdating this will
be saved: "čćđšž"

The code used to write into the db is as follows:
<?php
include('config.php');
include('adodb/adodb.inc.php');

if ($_REQUEST['v'] == $_REQUEST['verification']) {
$record = array(
'c_word_id' =$_REQUEST['word_id'],
'c_author_name' =$_REQUEST['name'],
'c_author_email' =$_REQUEST['email'],
'c_datetime' =strftime('%Y-%m-%d %H:%M:%S', strtotime('now')),
'c_text' =$_REQUEST['comment_text']
);

$db = NewADOConnection('mysql');
$db->Connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
$insertSQL = $db->AutoExecute('gim_comments', $record, 'INSERT');
You can see how the site behaves here: http://gimnazije.com/gimnazija_jagodina

Thanks!

Ira

Jun 27 '08 #1
3 2172
..oO(Ir*******@gmail.com)
>I am trying to fix PHP code developed by somebody else and my
knowledge of PHP is very limited so I'd appreciate any help.

I have a MySQL database configured to accept UTF-8 in all fields.

When I update the database with Unicode via phpMyAdmin web interface I
am able to write and save unicode values in all fields.

However when i try to update the database via web I am not
successful.

For example, if I enter "???šž" into the field I am updating this will
be saved: "Ä?ćđšž"

The code used to write into the db is as follows:
Your very first query after establishing the connection to the DB should
be

SET NAMES 'utf8'

to set the transfer encoding. Without that your UTF-8 characters won't
make it into the DB properly.

Micha
Jun 27 '08 #2
Micha - thanks, as you suggested mysql_query("set names 'utf8'"); did
the trick. I kept typing utf-8 for a while which was a mistake, it
seems that only utf8 works. Thanks again! Ira
Jun 27 '08 #3
On Wed, 4 Jun 2008 00:11:27 -0700 (PDT), Ir*******@gmail.com wrote:
Micha - thanks, as you suggested mysql_query("set names 'utf8'"); did
the trick. I kept typing utf-8 for a while which was a mistake, it
seems that only utf8 works. Thanks again! Ira
Yup, only "utf8" works (at least for now). You'll also want to
incorporate it into pretty much every call that may establish a new
connection. If you've a library of functions that you require_once for
every page that hooks up the databse, put it right after you're sure
you've got a connection that's properly signed in. if you've got
mysql_connect() calls scattered around, put a "SET NAMES utf8"
submission after every one.

--
78. I will not tell my Legions of Terror "And he must be taken alive!" The
command will be "And try to take him alive if it is reasonably practical."
--Peter Anspach's list of things to do as an Evil Overlord
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bill Eldridge | last post by:
I'm trying to grab a document off the Web and toss it into a MySQL database, but I keep running into the various encoding problems with Unicode (that aren't a problem for me with GB2312, BIG 5,...
2
by: Vincent Bouret | last post by:
Hi, I have read that Unicode (UTF-8) was not enabled by default in the mysql-4.1.0-alpha binaries. How can I enable it? What should I change in the code to do so? Thanks Vincent
0
by: jerome iffrig | last post by:
Hi, I am willing to setup my MySQL tables so they can hold international strings (English, French, German and Spanish). I understand that Unicode character coding is a good candidate to do so....
0
by: Andy Fish | last post by:
Hi, I have ported a .NET application which supports unicode from MS SQL Server to mysql. The .net framework itself is unicode throughout and I am using utf-8 innodb tables in mysql. When...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
4
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have created a populated a Access...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
1
by: erikcw | last post by:
Hi, I'm trying to insert some data from an XML file into MySQL. However, while importing one of the files, I got this error: Traceback (most recent call last): File "wa.py", line 304, in ?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.