473,325 Members | 2,671 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,325 software developers and data experts.

ŸT


I create a charset=big5 collate=big5 table to store Chinese characters
in big5 code. However, the INSERT sql failed when the character is
0x9f54. Why? If the value needs to be escaped, what function should I use?

--
iTech Consulting Co., Ltd.
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
Mar 15 '07 #1
8 1831
Man-wai Chang wrote:
>
I create a charset=big5 collate=big5 table to store Chinese characters
in big5 code. However, the INSERT sql failed when the character is
0x9f54. Why? If the value needs to be escaped, what function should I use?
What database are you using? Different databases have different functions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 15 '07 #2
>I create a charset=big5 collate=big5 table to store Chinese characters
>in big5 code. However, the INSERT sql failed when the character is
0x9f54. Why? If the value needs to be escaped, what function should I
use?
What database are you using? Different databases have different functions.
[chang@localhost ~]$ rpm -qa | grep sql
libdbi-dbd-mysql-0.7.1-3
sqlite-3.1.2-3
mysql-4.1.20-1.FC4.1
mysqlclient10-3.23.58-6
php-mysql-5.0.4-10.5
python-sqlite-1.1.6-1
postgresql-libs-8.0.8-1.FC4.1
mysql-devel-4.1.20-1.FC4.1
mysql-server-4.1.20-1.FC4.1
[chang@localhost ~]$ rpm -qa | grep php
php-ldap-5.0.4-10.5
php-gd-5.0.4-10.5
php-dbase-5.0.4-3.fc4
php-pear-5.0.4-10.5
php-mysql-5.0.4-10.5
php-5.0.4-10.5
--
iTech Consulting Co., Ltd.
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288

<?

class MYSQL {
private $fhandle;
var $row;
function MYSQL($host,$db,$usr,$pwd) {
$this->fhandle=mysqli_connect($host,$usr,$pwd,$db)
or die(mysqli_error());
$this->query("set names big5;");
$this->query("set character_set_client=big5;");
}
function query($sql_str) {
$this->row=mysqli_query($this->fhandle, $sql_str)
or die(mysqli_error($this->fhandle));
}
function affected_rows() {
return mysqli_affected_rows($this->row);
}
function num_rows() {
return mysqli_num_rows($this->row);
}
function fetch_assoc() {
return mysqli_fetch_assoc($this->row);
}
function __destruct() {
mysqli_close($this->fhandle);
}
function begin_tran() {
mysqli_autocommit($this->fhandle, FALSE);
}
function commit() {
mysqli_commit($this->fhandle);
mysqli_autocommit($this->fhandle, TRUE);
}
function rollback() {
mysqli_rollback($this->fhandle);
mysqli_autocommit($this->fhandle, TRUE);
}
}

function showcode($cChar) {
return "[".ord(substr($cChar,0,1)).".".ord(substr($cChar,1, 1))."]";
}
$target=new MYSQL("localhost","order_dev","root","123456");

$fhandle=dbase_open("canton.DBF",0);
if ($fhandle) {
$reccount=dbase_numrecords($fhandle);
echo "input count: ".$reccount."\n";
# clear table
$target->query("drop table canton");
$target->query(
"create table canton ("
. " big5 char(2) collate big5_bin not null,"
. " unicode char(20) not null,"
. " thekey char(6) collate big5_bin ,"
. " canton char(10) collate big5_bin ,"
. " changjei char(10) collate big5_bin,"
. " touched integer collate big5_bin,"
. " primary key (big5)"
. " ) default charset=big5 collate=big5_bin;"
);
for ($ii=1; $ii<=$reccount; $ii++) {
$row=dbase_get_record_with_names($fhandle,$ii);
$ss=$row['BIG5'];
$tt="0x".dechex(ord(substr($ss,0,1))).dechex(ord(s ubstr($ss,1,1)));
echo $ss.$tt."\n";
$target->query("select * from canton where big5=".$tt."");
$yy = $target->num_rows();
if ($yy>0) {
$query="update canton set touched="
. $row["TOUCHED"]
. " where big5=" . $tt . "";
}
else {
$query="insert into canton ("
. " big5,"
. " unicode,"
. " thekey,"
. " changjei,"
. " canton,"
. " touched "
. ") values ("
. "".$tt.","
. "'mb_convert_encoding',"
. "'".$row["THEKEY"]."',"
. "'".$row["CHANGJEI"]."',"
. "'".$row["CANTON"]."',"
. $row["TOUCHED"]
. ")";
}
$result=$target->query($query);
}
$result=$target->query("select count(*) as cnt from canton");
$yy = $target->fetch_assoc();
echo "output count: ".$yy['cnt']."\n";
dbase_close($fhandle);
}
?>

Mar 15 '07 #3
I just found that it would work if I use binary(2) rather char(2) for
the big5 column. But I found something using char(2) to store big5
codes. Why can't my program work?

--
iTech Consulting Co., Ltd.
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
Mar 15 '07 #4
Argh... sorry.

I found the bug. It's in the data. Sorry. I don't know why I missed it...

--
iTech Consulting Co., Ltd.
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
Mar 15 '07 #5
"Man-wai Chang" <to***********@gmail.comwrote in message
news:45********@127.0.0.1...
>
I create a charset=big5 collate=big5 table to store Chinese characters in
big5 code. However, the INSERT sql failed when the character is 0x9f54.
Why? If the value needs to be escaped, what function should I use?

I'm guessing it has something to do with the fact that 0x54 is ASCII single
quote ' .

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Mar 15 '07 #6
I'm guessing it has something to do with the fact that 0x54 is ASCII single
quote ' .
Thanks. What should I do if I really need to add it into it?
mysql_escape_string?

--
iTech Consulting Co., Ltd.
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
Mar 15 '07 #7
"Man-wai Chang" <to***********@gmail.comwrote in message
news:45********@127.0.0.1...
>I'm guessing it has something to do with the fact that 0x54 is ASCII
single quote ' .

Thanks. What should I do if I really need to add it into it?
mysql_escape_string?

You can try that (or mysql_real_escape), I don't know how it works with a
multibyte string, I haven't got any experience on that matter. Why don't you
try it and see if it works? If you do test it, please share your experience
with the group and if you find a working solution.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Mar 15 '07 #8
Kimmo Laine wrote:
"Man-wai Chang" <to***********@gmail.comwrote in message
news:45********@127.0.0.1...
>>I'm guessing it has something to do with the fact that 0x54 is ASCII
single quote ' .
Thanks. What should I do if I really need to add it into it?
mysql_escape_string?


You can try that (or mysql_real_escape), I don't know how it works with a
multibyte string, I haven't got any experience on that matter. Why don't you
try it and see if it works? If you do test it, please share your experience
with the group and if you find a working solution.
If the table is set up with the correct charset,
mysql_real_escape_string() should work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 15 '07 #9

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

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.