Chakrit 的个人资料ชาคริต照片日志列表更多 工具 帮助

K. Chakrit

职业
地点
兴趣
me
列表

ชาคริต

8月23日

อืม นอนไม่หรับ

 
 http://theme60.eiei.net/mytheme3/    <--  กับความพยายามมาสองปีและเดือนละ 5 พัน
 
--------------------------------------
 
จุดมุ่งหมายอันยิ่งใหญ่ของมนุษคือการเข้าใจในรัก   <-- กับความงงๆ
ความรักไม่ได้อยู่ที่คนอื่น แต่อยู่ในตัวของเรา
เราปลุกมันขึ้นมา
และเพื่อจะปลุกเจ้าความรักนี้ เราจำเป็นต้องมีคนอื่น
โลกนี้จะมีความหมายก็ต่อเมื่อเรามีใครสักคน
ที่จะแบ่งปันความรู้สึกด้วยได้เท่านั้น
 
--------------------------------------
 
     อืม...
    V
 

Fergie Big Girls Don't Cry Lyrics


Da Da Da Da
The smell of your skin lingers on me now
You're probably on your flight back to your hometown
I need some shelter of my own protection baby
Be with myself in center, clarity
Peace, Serenity

I hope you know, I hope you know
That this has nothing to do with you
It's personal, myself and I
We got some straightening out to do
And I'm gonna miss you like a child misses their
blanket
But I've gotta get a move on with my life
It's time to be a big girl now
And big girls don't cry
Don't cry,
Don't cry,
Don't cry

The path that I'm walking, I must go alone
I must take the baby steps til I'm full grown,full
grown
Fairy tales don't always have a happy ending do they
And I forseek the dark ahead if I stay

I hope you know, I hope you know
That this has nothing to do with you
It's personal, myself and I
We got some straightening out to do
And I'm gonna miss you like a child misses their
blanket

But I've gotta get a move on with my life
It's time to be a big girl now
And big girls don't cry

Like a little school mate in the school yard
We'll play jacks and uno cards
I'll be your best friend and you'll be mine
Valentine
Yes you can hold my hand if you want to
'cause I wanna hold yours too
We'll be playmates and lovers and share our secret
worlds
But it's time for me to go home
It's getting late, dark outside
I need to be with myself in center, clarity
Peace, Serenity

I hope you know, I hope you know
That this has nothing to do with you
It's personal, myself and I
We got some straightening out to do
And I'm gonna miss you like a child misses their
blanket
But I've gotta get a move on with my life
It's time to be a big girl now
And big girls don't cry
Don't cry,
Don't cry,
Don't cry

La Da Da Da Da Da (more)

 

 

 

You Give Me Something  [James Morrison]

 

You want to stay with me in the morning

You only hold me when I sleep,

I was meant to tread the water

Now I've gotten in too deep,

For every piece of me that wants you

Another piece backs away.

 

'Cause you give me something

That makes me scared, alright,

This could be nothing

But I'm willing to give it a try,

Please give me something

'Cause someday I might know my heart.

 

You already waited up for hours

Just to spend a little time alone with me,

And I can say I've never bought you flowers

I can't work out what the mean,

I never thought that I'd love someone,

That was someone else's dream.

 

 

'Cause you give me something

That makes me scared, alright,

This could be nothing

But I'm willing to give it a try,

Please give me something,

'Cause someday I might call you from my heart,

But it might me a second too late,

And the words I could never say

Gonna come out anyway.

 

'Cause you give me something

That makes me scared, alright,

This could be nothing

But I'm willing to give it a try,

Please give me something,

'Cause you give me something

That makes me scared, alright,

This could be nothing

But I'm willing to give it a try,

Please give me something

'Cause someday I might know my heart.

Know my heart, know my heart, know my heart

 

 

 

3月1日

ส่งฝน

 
วันนี้ไปส่งฝนที่ปราจีน ไปดูโรงงาน AA. ดูบ้านพัก แล้วก็สถานที่ทั่วๆไปนั้น
หลงทางนิดหน่อยช่วงเช้า  GPS ทำเหตุนะนนท์
วนหาหอ, ดูบ้านพัก ออกจะเก่าๆ หน่อย
ร้านอาหารญี่ปุ่น  คนญี่ปุนเพียบ อร่อยดี
เซ็นสัญญา วิวสวย บริษัทกว้างดี ไม้เพียบ
ทำความสะอาดขนของ  สะอาดแล้วก็ o นะ
ไป bigC ซื้อของ
ฝนเลี้ยงอาหารเย็น  hot spot  อร่อยกว่า mk นะ( อาจจะเพราะไม่ค่อยกิน )
ต่อโต๊ะวางของ
กลับถึง กทม 4 ทุ่มครึ่ง
2 ชมกับระยะทาง 180 km
8月2日

วันสงกราน

วันสงกรานปีนี้ ต่างจาก 22 ปีที่ผ่านมา  เพราะว่า ได้เล่นน้ำสงกรานกับเขาด้วย
มีโอกาศได้ไปเที่ยวบ้านเพื่อนอ่ำ ด้วยรถนนท์ ขับกันไปถึงอุตลริต แม้ระยะทางจะไกลหน่อยแต่ก็รู้สึกว่าไม่นาน เพราะหรับมาตลอดเป็นระยะๆนะ
แล้วก็ได้เจอ..เหตุการณ์.. ได้เล่นน้ำสงกรานด้วย นุกดี...
 
( เริ่มเขียนไว้นานแล้ว แต่ก็ไม่เสร็จ กะว่าจะมาแก้  แต่เวลาผ่านไปๆ  ข้อความตามความตั้งใจเดิมที่อยากจะเขียน  มันก็เปลี่ยนไป )
 
 
 
4月21日

ไม่มีคำพูด

---  ลบทิ้งแล้วล่ะจ๊ะ ---
 
.
.
.
.
.
.
 
3月28日

ให้กับทุกคนที่ดิ้นรน ต่อสู้กับตัวเอง

 
 
เขีนเองไม่ค่อยเป็น แต่พอดีอ่านแล้ว มันตรงกับ เพื่อนหลายคน ก็เลย ทำ link ให้
ส่วนตัวเองอ่านแล้วรู้สึก ว่าอย่างไรดี บอกไม่ถูก มัน......
 
- ให้กับเพื่อนที่ ดิ้นรน ค้นหา คำตอบของชีวิตของตัวเอง
- ให้กับเพื่อนที่ ดิ้นรน ค้นหา คำตอบของชีวิตของคนที่รัก
 
และขอให้เพื่อน หัวใจแข็งแรงในเร็ววัน
 
คริต
1月24日

วันที่ว่างๆ

วันนี้ ว่างๆ ครับ  
ไม่ได้ว่างจากงาน หรือ อะไร แค่ทำตัวเองให้ว่างๆ เอาหัวออกไปแล้ว เข้าไปอ่าน blog ของเพื่อนๆ ตามรายชื่อใน msn ที่ไล่เรียงลงมา ทีละคน ทีละคน  หนุกดีครับ หลากหลายดี ทำให้หายเครียดกับงานไปได้  เรื่องของเพื่อนๆ พี่ๆ มีตั้งแต ลงหนังสือพิมพ์, เรื่องในบริษัท, ดาดา, ชีวิตประจำวัน, สังคม, บ่น(อย่างที่คริตทำอยู่) ,  แล้วก็การเขียนโปรแกรม(เพื่อนใน list ส่วนใหญ่เรียนมาด้านนี้)  บางคนเขียนแบบบรรยาย , แบบสรุปเหตุการ, แบบเขียนไปเรื่อยๆ นุกดี...
 
ว้าว ไปรู้จะเขียนอะไร ดี
เอาข่าวในเกี่ยวกับโทรศัพท์มาฝากแล้วกัน
- AIS ถูกขายแล้วนะ  ล้อเล่น เพื่อนๆ รู้กันหมดแล้วแหละ ข่าวเก่า
- จะมีการเพิ่มเบอร์โทรศัพท์จาก 9 หลัก เป็น 10 หลัก ภายในก่อนกลางปีนี้
 
 
เล่าเรื่องซึ้งๆ จากสนามบินที่ปักกิ้งให้ฟังดีกว่า
  พอดีปลายปีที่แล้วมีโอกาสพึ่งใบบุญบริษัทเลยได้ไปปักกิ่ง 5 วัน ไปดูบริษัทโทรคมที่ใหญ่เป็นอันดับสองของจีน แล้วก็ ....(ทั่วๆ ข้ามเลยแล้วกัน )....คริตประทับใจมากอยู่ตอนหนึ่ง คือ ตอนที่กำลังจะขึ้นเครื่องกลับไทยนี่แหละ
   ระหว่างที่เข็นรถขนสัมภาระไปตามทางเพื่อไปเข้าคิว ก็ไปเห็นสาวน้อยคนหนึ่ง(เพื่อนๆอย่าคิดมาก) กำลังเข็นรถมาเหมือนกัน โดยมีชายอีกคนลากกระเป๋าใบกลางๆอีกใบตามหลัง และหญิงเดินมาด้วยกันอีกด้าน ดูจากอายุและท่าทางแล้ว เดาออกได้ไม่ยากว่าเป็นพ่อแม่ลูกกัน เดินไปเรื่อยจนมาต่อคิวเพื่อตรวจพาสปอร์ต คิวไม่ยาวมาก มองดูซ้ายขวาก็จะมีประมาณ 40-50 คนรอคิว โดยแบ่งเป็น 7-8 แถว.  บังเอิญพ่อแม่ลูกก็มาต่อที่ คิวข้างๆ คริต พ่อเขายกกระเป๋าขึ้นวางซ้อนขึ้นบนรถลาก ขณะที่แม่กำลังจับมือแล้วก็กำมือลูกสาวไว้แน่
     คิวค่อยๆขยับขึ้นไป พ่อแม่ลูกก็เริ่มจะพูดกัน  จับใจความได้ว่าลูกเขาจะไปเรียนต่อ (พอฟังออก 2-3คำอ่ะนะ) สังเกตุจากกระเป๋า การแต่งตัว พวกเขาไม่น่าจะเป็นคนมีเงินมาก ตามฐานะและรายได้คิดว่าค่าตั๋วคงจะแพงมากสำหรับเขา(เทียบจากค่าเงินเดือนข้าราชการทั่วๆประมาณ 3,500)  ทำให้รู้สึกว่าการไปครั้งนี้ ลูกสาวคงจะเป็นแบบเรียนเก่งแล้วได้ทุน แล้วก็คงจะไม่มีโอกาศกลับมาในช่วงปิดเทอม คนจีนส่วนใหญ่จะมีลูกแค่คนเดียว
     คิวขยับขึ้นไปจนเหลืออีกคนก็จะถึง พ่อแม่ลูกสามคนนี้แล้ว  ลูกสาวก็หันกลับมา (ตาแดงมาก) แล้วก็..กอดแม่ แม่ที่ตาแดงๆตั้งแต่ตอนเริ่มต่อคิว ก็กลั้น น้ำตาไม่อยู่ ไหลเป็นทางเลย คุณพ่อยืนอยู่ข้างหลังเอามือวางบนหัวไหล่ลูกสาว แล้วก็ได้ยินเสียงแม่บอกอะไรไปเรื่อยๆ กับลูกสาวเหมือนเป็นการย้ำอะไรสักอย่าง ลูกก็พยักหน้า, พยักหน้า ที่ละครั้งๆ ตามคำพูดของแม่..  คนที่ต่อคิวก่อนเข้าไปแล้ว ตอนนี้ถึงคิวของ ลูกสาวคนนี้แล้ว คริตสังเกตเห็นเจ้าหน้าที่ไม่กล้าเรียก ได้แต่รอ.    คนที่ต่อคิวเขาก็ไม่กล้าทัก ลูกกับแม่กดอยู่อีก 4-5วิ ลูกสาวก็แยกออกมา พร้อมกับเช็ดน้ำมูกน้ำตา ที่เต็มหน้า เจ้าหน้าที่ใช้พลิกเอกสารดูสองที ประทับตราแล้วก็ยื่่นคืนให้ ลูกสาวก็รับและหันมาจะเข็นรถไป พ่อที่ยืนข้างๆก็รีบช่วยดันรถให้ สังเกตุเห็นหน้าพ่อแล้วพยายามกระพริบตาถี่ๆ เพื่อไม่ไห้นำตาไหลออกมา ลูกสาวก็เหมือนจะรู้ใจพ่อ ก้มหน้าไม่กล้ามองหน้า และลูกสาวก็ค่อยๆเขนรถผ่านด่านคนตรวจเข้าไปช้าๆที่ละก้าว แม่เขายื่นมือไปแตะที่แขนลูกสาวไว้ แขนกับมือค่อยๆแยกจากกันตามที่ลูกเดินห่างออกไป (ภาพ slow motion เหมือนในหนังเลย) ตอนนี้พ่อเริ่มน้ำตาจะไหลแล้ว ลูกสาวก็เขนผ่านไปแล้ว ตอนนี้คริตเองก็กำลังตรวจเอกสาร แล้วก็ผ่านด้านมา หันไปดู เห็นลูกสาวยืนโบกมือให้แม่ ส่วนพ่อยืนหันหลัง เอาแขนเสื้อเช็ตน้ำตา ...
 
    สิ่งที่ดีที่สุดในชีวิตก็คือ  รู้ว่าเรารักใคร ....
 
 
 
กลับหอล่ะก้า

 

-----------------------------------------------------------

แก้คำผิดแล้วครับ  ขอบคุณ อั้ม มาก

? ทำไมเขาไม่ออกแบบภาษาไทยให้มีคำน้อยเท่ากับ keyword ของ java น่ะ  ????....

 

1月5日

JAVA call Command dos

 

http://www.oracle-base.com/articles/8i/ShellCommandsFromPLSQL.php

JAVA call Command dos

Shell Commands From PL/SQL

Using a Java stored procedure it is possible to perform shell commands from PL/SQL:

Create the Java Stored Procedure

First we need to create the Java class to perform the shell command:
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
  public static void executeCommand(String command) {
    try {
      String[] finalCommand;
      if (isWindows()) {
        finalCommand = new String[4];
        // Use the appropriate path for your windows version.
        //finalCommand[0] = "C:\\windows\\system32\\cmd.exe";  // Windows XP/2003
        finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";  // Windows NT/2000
        finalCommand[1] = "/y";
        finalCommand[2] = "/c";
        finalCommand[3] = command;
      }
      else {
        finalCommand = new String[3];
        finalCommand[0] = "/bin/sh";
        finalCommand[1] = "-c";
        finalCommand[2] = command;
      }
  
      final Process pr = Runtime.getRuntime().exec(finalCommand);
      new Thread(new Runnable(){
        public void run() {
          BufferedReader br_in = null;
          try {
            br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String buff = null;
            while ((buff = br_in.readLine()) != null) {
              System.out.println("Process out :" + buff);
              try {Thread.sleep(100); } catch(Exception e) {}
            }
            br_in.close();
          }
          catch (IOException ioe) {
            System.out.println("Exception caught printing process output.");
            ioe.printStackTrace();
          }
          finally {
            try {
              br_in.close();
            } catch (Exception ex) {}
          }
        }
      }).start();
  
      new Thread(new Runnable(){
        public void run() {
          BufferedReader br_err = null;
          try {
            br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
            String buff = null;
            while ((buff = br_err.readLine()) != null) {
              System.out.println("Process err :" + buff);
              try {Thread.sleep(100); } catch(Exception e) {}
            }
            br_err.close();
          }
          catch (IOException ioe) {
            System.out.println("Exception caught printing process error.");
            ioe.printStackTrace();
          }
          finally {
            try {
              br_err.close();
            } catch (Exception ex) {}
          }
        }
      }).start();
    }
    catch (Exception ex) {
      System.out.println(ex.getLocalizedMessage());
    }
  }
  
  public static boolean isWindows() {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
      return true;
    else
      return false;
  }

};
/

show errors java source "Host"

Publish the Java call specification

Next we publish the call specification using a PL/SQL "wrapper" PL/SQL procedure:
CREATE OR REPLACE PROCEDURE Host_Command (p_command  IN  VARCHAR2)
AS LANGUAGE JAVA 
NAME 'Host.executeCommand (java.lang.String)';
/

Grant Privileges

The relevant permissions must be granted from SYS for JServer to access the file system:
EXEC Dbms_Java.Grant_Permission('SCHEMA-NAME', 'java.io.FilePermission', '<>', 'read ,write, execute, delete');

EXEC Dbms_Java.Grant_Permission('SCHEMA-NAME', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');

EXEC Dbms_Java.Grant_Permission('SCHEMA-NAME', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
The affects of the grant will not be noticed until the grantee reconnects.

Test It

Finally we call the PL/SQL procedure with our command text:
SET SERVEROUTPUT ON SIZE 1000000
CALL DBMS_JAVA.SET_OUTPUT(1000000);
BEGIN
  Host_Command (p_command => 'move C:\test1.txt C:\test2.txt');
END;
/
The same result could be achieved with COM Automation but in my opinion this method is much neater.

Known Issues

Depending on the environment, the process may continue running as a zombie after the command has been executed, even if the destroy() method is called manually. If this happens the process is only cleaned up when the session ends. Under normal circumstances this doesn't represent a problem, but when called as part of a job the zombie processes will only die when the Job Queue Coordinator is stopped.

Hope this helps. Regards Tim...

Back to the Top.
12月19日

Php操作oracle数据库指南-本人原创

http://phpup.com/phparticle/show-article-431/ Php操作oracle数据库指南-本人原创,经验总结,不能不看 作者:Admin | 文章出处:未知 | 阅读次数:30 | 发布日期:2004-10-24 本人由于工作关系使用Oracle数据库,发现这里用的人不多,但时常发现有人提的关于PHP操作ORACLE数据库的问题得不到回答,我也曾问过几个,但也无人响应,因此决定把本人在工作中积攒起来的一些技巧、经验奉献出来,希望对使用oracle数据库的人有所帮助。一、配置环境:访问Oracle8以上的数据库需要用到Oracle8 Call-Interface(OCI8)。这个扩展模块需要Oracle8 的客户端函数库,因此需要你要连接远程Oracle数据库的话,还要装上Oracle的客户端软件-可以到Oracle网站上免费下载- http://www.oracle.com,这是许多初学者常常忽略的,因此如果看了这篇文章,就不要在论坛上再提“为什么我连接不上Oracle数据库”之类的问题了。(1)首先确认安装了Oracle8i客户端,然后用net8 assistant(客户端软件提供)建立一个服务命名,注意服 务名是oracle数据库的sid,可查询initsid文件里的server_names得到。(2)在php.ini中把 ;extension=php_oci8.dll 前面的注释符号“;”去掉,使php能够加载支持oracle的模块 。并把php_oci8.dll拷贝到你的windows2000 server安装目录下的system32子目录。如d:winntsystem32,重 新启动你的机器。(3)写个测试文件试一下是否能正确连接(假如服务名sid是test):这里scott用户是Oracle自带的无须你自己建立了,只要把下面这个文件放到你的WEB根目录就可以了。如果显 示到数据库中的数据,则说明连接正常,如果不行,你还要检查前几步有哪些地方做错了。 test.php ERROR - Could not parse SQL statement."; exit; } OCIExecute($stmt); while( OCIFetchInto($stmt, &$result_array) ) { echo "EMPno=$result_array[0];Ename=$result_array[1];JOB=$result_array[2];MGR=$result_array[3]
"; } ?>二、用PHP执行Oracle存储过程(1)用sqlplus连接后,建立一个存储过程: CREATE OR REPLACE PROCEDURE inoutdemo ( par_in IN VARCHAR2, par_in_out IN OUT VARCHAR2, par_out OUT VARCHAR2) IS BEGIN par_out := par_in; par_in_out := par_in || ' ' || par_in_out; END; (2)PHP文件: sptest.php
"; echo "in=".$in."
"; echo "inout=".$inout."
"; echo "out=".$out."
"; ?> 三、Oracle数据库的分页 Oracle虽然不象Mysql有limit可用,十分方便,但也有自己的处理方法,它特殊的rownum对分页有很重要的作 用。分页可有很多种方法,其中最常用的是用minus。如要显示n1-n2记录可写为:(1)SELECT * FROM tablename WHERE rownum <= n2 minus SELECT * FROM tablename WHERE rownum < n1 注意:该语句不能使用order by,否则报错。(2)把指针下移的办法如:其中:$page是当前页;$pagesize是每页显示的记录数 for($i=0;$i<($page-1)*$pagesize;$i++) { @ocifetch($stmt); } 然后再用ocifetch($stmt)取出的数据就是你要显示的记录了(3)对于有复杂查询语句并用order by来排序的,可使用下面方法解决: SELECT TABLE_NAME,TABLE_TYPE FROM( SELECT ROWNUM ROWSEQ,X.* FROM (SELECT * FROM CAT ORDER BY TABLE_TYPE) X) WHERE ROWSEQ BETWEEN n1+1 AND n2; 本人最喜欢的是第三种,也推荐大家使用,非常方便的啊。呵呵。其它方法就不介绍了,很麻烦,使用了Oracle游标之类的东东,不太适合PHP使用。 四、特殊字符的插入处理对于一些字符如单引号'在Oracle里是不能用addslashes处理的,但可以使用Oracle的CHR函数或再加个单引号 。如:SQL>insert into table values('it'||chr(39)||'s a test')); 或 SQL>insert into table values('it''s a test')); 显示: it's a test. 五、PHP和Oracle的事务处理 OCIExecute()函数:int OCIExecute ( int statement [, int mode] ) 第二个参数mode共有两个:缺省为OCI_COMMIT_ON_SUCCESS,可省略。OCI_DEFAULT 表示用事务(Transation) 提交,不自动提交。如果你在程序中如果有两个操作数据库的语句需要同时成功执行,有一个失败就要rollback的话,可这样写: $conn=OCILogon($username,$password,$sid); //first sentence $Sql = "insert into tablename values()"; $stmt=OCIParse($conn,$Sql); $result=OCIExecute($stmt, OCI_DEFAULT); if (!$result) { OCIRollback($conn);//不成功则回滚 OCIFreeStatement($stmt); //释放资源 OCILogoff($conn); } //second sentence $Sql = " update tablename set.."; $stmt=OCIParse($conn,$Sql); $result=OCIExecute($stmt, OCI_DEFAULT); if (!$result) { OCIRollback($conn);//不成功则回滚 OCIFreeStatement($stmt); //释放资源 OCILogoff($conn); } OCICommit($conn);//如果都成功则提交 OCIFreeStatement($stmt); //释放资源 OCILogoff($conn); 六、用PHP操纵Oracle的LOB类型的数据(含图片的存储与显示处理)对PHP程序员来讲,Oracle最令人头痛的莫过于使用LOB来处理图片了。 1。PHP操作BLOB:先建立一个表用于保存图片。用户上传的图片文件存放到BLOB中 CREATE TABLE PICTURES ( ID NUMBER, IMGTYPE, VARCHAR2(60), DESCRIPTION VARCHAR2(100), PICTURE BLOB ); 如果要实现ID的自动增加,再建一个SEQUENCE: CREATE SEQUENCE PIC_SEQ; PHP程序-插入部分: save(fread($fp, filesize($lob_upload))); //fclose($fp ); //释放LOB对象 OCIFreeDesc($lob); OCIFreeStatement($stmt); OCILogoff($conn); ?> 小技巧:在sqlplus里可用select dbms_lob.getlength(picture) from pictures;查看文件是否已存入到数据 库或在PHP程序里用strlen()函数查看。 PHP程序-显示部分(getpicture.php): load(); } //可用strlen($result[1]->load()) 查看图片的大小以确定图片是否正确存入到数据库。 ?> 在需要显示图片的地方只要: 放在Oracle LOB中的图片就能显示图片了有的网上文章写用返回LOB值而非描述符的方法显示,我没有试成功,大家可以试下代码如下: if (OCIFetchInto($stmt, $result, OCI_ASSOC+OCI_RETURN_LOBS)) { echo "Content-type: " . StripSlashes($result[imgtype]); echo StripSlashes($result[picture]); } 2。PHP操作CLOB: Oracle有一种数据类型叫VARCHAR2,用来表示不定长的字符串。VARCHAR2也是Oracle公司推荐使用的类型。但 使用VARCHAR2有个问题:最大只能表示4000个字符,也就相当于2000个汉字。如果你的程序中某个字符串的长 度要大于2000个汉字,用VARCHAR2就不能满足要求了。这时候,你可以尝试使用CLOB。CLOB和BLOB的最大长度 是4GB。 下面是示例(参考了PHP英文版的手册): save($clobtext)) { OCICommit($conn); echo "提交成功"; } else { print_r(OCIError($stmt)); } //释放资源 $clob->free(); OCIFreeStatement($stmt); ?>
11月24日

เมื่ออักษรภาษาไทยกลายเป็น ?????? ใน MySQL

 
 
 
 
Home arrow บทความ arrow บทความเกี่ยวกับ PHP arrow เมื่ออักษรภาษาไทยกลายเป็น ??????

เมื่ออักษรภาษาไทยกลายเป็น ??????
อังคาร, 15 กุมภาพันธ์ 2005

ผมเคยติดตั้งและใช้งาน PHP และ MySQL มาหลายครั้งหลายหน ไม่ว่าจะเป็นการติดตั้งบน Linux หรือ Windows ทั้งที่ Compile เองและติดตั้งแบบ package  ซึ่งการติดตั้งบน Windows ดูจะติดตั้งอย่างสะดวกและรวดเร็วมากขึ้น เพราะมีผู้ทำโปรแกรมช่วยติดตั้ง Apache PHP และ MySQL อัตโนมัติ เช่น AppServ (www.appservnetwork.com) และ XAMPP (http://www.apachefriends.org/en/index.html) เป็นต้น

แต่คราวนี้ผมเจอปัญหาหลังจากการติดตั้ง Apache PHP และ MySQL บนระบบปฏิบัติการ Windows เพราะเมื่อทดลอง query ข้อมูลที่เป็นภาษาไทยจาก MySQL กลับพบว่าได้ผลลัพธ์ในการแสดงผลภาษาไทยที่ไม่ถูกต้อง คือตัวอักษรภาษาไทยจะแสดงออกมาเป็นเครื่องหมายคำถาม (?) ทั้งหมด ในขณะที่ผมได้เพิ่ม option ที่เกี่ยวกับการ set character ให้เป็นภาษาไทยใน my.ini แล้ว ดังตัวอย่างต่อไปนี้

[mysqld]
default-character-set=tis620

หลังจากที่ได้ทำการตรวจสอบแล้วในฐานข้อมูล MySQL โดยใช้โปรแกรม เช่น MySQL-Front (http://www.mysqlfront.de/) แล้วก็พบว่าข้อมูลที่เก็บอยู่ก็เป็นภาษาไทยถูกต้อง และเมื่อลองดูตัวแปรต่างๆ ที่เกี่ยวข้องกับ character ต่างๆ ก็พบค่าต่อไปนี้

- character_set_client = tis620
- character_set_connection = tis620
- character_set_database = tis620
- character_set_results = tis620
- character_set_server = tis620
- character_set_system = utf8
- collation_connection = tis620_thai_ci
- collation_database = tis620_thai_ci
- collation_server = tis620_thai_ci

เมื่อลองไปค้นในเว็บไซท์ของ MySQL ในส่วนที่เกี่ยวข้องกับกลุ่มอักขระ (character set) ก็พบส่วนที่เกี่ยวข้องกับกลุ่มอักขระ ใน Chapter 10. Character Set Support (http://dev.mysql.com/doc/mysql/en/charset.html) ซึ่งได้อธิบายความหมายของ Character set ไว้ว่าคือ กลุ่มของสัญลักษณ์และการ encode อักขระต่างๆ ส่วน collation หมายถึง กลุ่มของกฎเกณฑ์ที่ใช้ในการเปรียบเทียบอักขระต่างๆ ใน กลุ่มอักขระหนึ่งๆ สำหรับภาษาไทยมีกลุ่มอักขระคือ tis620 และมี collation คือ tis620_thai_ci

ทั้งนี้ระดับการใช้งานของ charcter set และ collation มีอยู่ด้วยกันทั้งหมด 4 ระดับคือ server database table และ connection สำหรับปัญหาที่ผมเจอนี้ ผมมุ่งประเด็นไปที่ connection โดยตั้งสมมติฐานว่าปัญหาของการแสดงผลภาษาไทยที่ผิดพลาดน่าจะเกิดระหว่างการติดต่อระหว่าง client (php script) กับ server (MySQL server)

สิ่งที่เกิดขึ้นระหว่างการติดต่อระหว่าง client และ server คือ client จะส่ง SQL statement เช่น query ต่างๆ ให้กับ server หลังจากนั้น server ก็จะตอบกลับ เช่น การส่งผลลัพธ์ของ SQL statement นั้นๆ กลับไปให้ client ในระหว่างที่มีการติดต่อกันนี้จะมีส่วนของ character set และ collation เข้ามาเกี่ยวข้อง คือ

  1. Character set ของ client ในขณะที่ส่ง query ให้กับ server: มีตัวแปรที่เกี่ยวข้องคือ character_set_client
  2. Character set ที่ server แปล query หลังจากที่ได้รับจาก client: ตัวแปรที่เกี่ยวข้องคือ character_set_connection และ collation_connection โดย server จะใช้ค่าของตัวแปร character_set_connection ในการแปล character set ของ query ที่ client ส่งมา ( character_set_client) ให้เป็นตามค่าที่กำหนดไว้ในตัวแปร character_set_connection
  3. Character set ที่ server จะทำการแปลก่อนที่จะส่งผลลัพธ์กลับไปให้แก่ client: ตัวแปรที่เกี่ยวข้องคือ character_set_results

ดังนั้นตัวแปรที่ควรจะทำการตรวจสอบก่อนก็คือ character_set_results ว่าค่าของตัวแปรนั้นเป็นค่าอะไรหรือเป็นค่าที่เกี่ยวข้องกับปัญหานี้หรือไม่  ผมทดสอบโดยการกำหนดค่าให้ chacter_set_results มีค่าเป็น tis620 ก่อนจะทำการส่ง query จริงๆ ไปให้แก่ MySQL  โดยการใช้คำสั่งต่อไปนี้

$charset = "SET character_set_results=tis620";
mysql_query($charset) or die('Invalid query: ' . mysql_error());

ผลปรากฎว่าการกำหนดค่าให้ตัวแปร character_set_results มีค่าเป็น tis620 ดังกล่าว สามารถช่วยแก้ปัญหาแสดงผลภาษาไทยที่ไม่ถูกต้องได้   นอกจากนี้สามารถใช้คำสั่งต่อไปนี้ในการแก้ปัญหาภาษาไทย คือ

  • SET NAMES 'tis620' ซึ่งมีค่าเทียบเท่ากับ
    • SET character_set_client='tis620'
    • SET character_set_results='tis620'
    • SET character_set_connection='tis620'
  • SET chracter_set_results=NULL  ซึ่งมีความหมายคือ ไม่ต้องการให้ server ทำการแปลงข้อมูลก่อนที่จะทำการส่งให้กับ client

สรุปแล้วปัญหาที่เกิดขึ้นน่าจะเกิดจากค่าของตัวแปร character_set_results ซึ่งถูกกำหนดให้เป็น character set ที่ไม่ใช่ tis620 ทำให้อักขระภาษาไทยที่ส่งกลับมาให้ client นั้นแสดงผลไม่ถูกต้อง  วิธีการแก้ปัญหาของผมในขณะนี้คือ ต้องแทรกคำสั่งที่กำหนดให้ character_set_results เป็น tis620 ก่อนที่จะทำการส่ง query จริงๆ ไปให้แก่ MySQL   ผมเองค่อนข้างงงว่าเหตุใดการกำหนดคำสั่ง default-character-set=tis620 ไม่สามารถแก้ปัญหานี้ได้  หากมีคำแนะนำหรือมีข้อเสนอแนะสามารถเขียนแจ้งมาได้นะครับที่ webmaster [a] phpconcept.com

หวังว่าบทความนี้จะช่วยแก้ปัญหาให้กับบางท่านได้นะครับ :)

อัพเดทล่าสุด ( อังคาร, 15 กุมภาพันธ์ 2005 )
 
 
11月5日

Fileupload with servlet (multipart/form-data)

 
ภาษาไทยครับ
 

在通过使用FileUpload组件上传的过程中,通过自己的调试,总结如下:
1)使用之前的准备,我用的是commons-fileupload-1.1-dev.jar和commons-io-1.1-dev.jar。
   解释一下:尽管有的资料解释是commons-fileupload-1.0-beta.jar和commons-beanutils.jar,通过调试的结果
   显示并不是需要commons-beanutils.jar文件,而是由于在parseRequest(request)的类有关继承于DiskFileItem
类。而他有private  org.apache.commons.io.output.DeferredFileOutputStream dfos。这样的就必须使用到commons-io-1.1-dev.jar。因此需要导入该包。否则就出classNotFound:.DeferredFileOutputStream的错误。

2)由于涉及文件,就涉及到文件系统。然而在java或应用服务器中对于文件系统的访问,就有一定的安全策略。
  需要将下列权限添加到您应用程序服务器的安全策略文件中:
permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
具体是添加到..\bea\weblogic81\server\lib\weblogic.policy中的.
否则会可能出如下异常错误:
 org.apache.commons.fileupload.FileUploadException:
java.lang.reflect.InvocationTargetException
at
org.apache.commons.fileupload.FileUpload.createItem(FileUpload.java:615)
at
org.apache.commons.fileupload.FileUpload.parseRequest(FileUpload.java:474)
at
org.apache.commons.fileupload.FileUpload.parseRequest(FileUpload.java:355)
....

3)对于不同的服务器,在调试的过程中会出各种不一样的结果。这个与具体的服务器有关。

4)由于FileUpload在不断的更新版本,它的很多方法已经不推荐使用了(这与该组件的不断的改进有关)。通过对最新的帮助文档和网上的资料写了一个标准的程序如下:
fileUpload文件:
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.*;
import java.util.*;
import java.util.regex.*;
import java.io.*;
import org.apache.commons.fileupload.servlet.*;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;

/*
 * 创建日期 2005-4-10
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */

/**
 * @author gaolong1
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class FileUpload extends HttpServlet {

 /**
  * Destruction of the servlet. <br>
  */
 private String uploadPath = "D:\\addnetFile\\"; // 用于存放上传文件的目录
    private File tempPath =new File("D:\\addnetFile\\tmp\\"); // 用于存放临时文件的目录
 public void destroy() {
  super.destroy(); // Just puts "destroy" string in log
  // Put your code here
 }

 /**
  * The doPost method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to post.
  *
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
  public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
   res.setContentType( "text/html; charset=GB2312");
  PrintWriter out=res.getWriter();
  System.out.println(req.getContentLength());
     System.out.println(req.getContentType());
   DiskFileItemFactory factory = new DiskFileItemFactory();
        // maximum size that will be stored in memory
        factory.setSizeThreshold(4096);
        // the location for saving data that is larger than getSizeThreshold()
        factory.setRepository(new File("d:\\File\\addnetFile\\temp"));

        ServletFileUpload upload = new ServletFileUpload(factory);
        // maximum size before a FileUploadException will be thrown
        upload.setSizeMax(1000000);
        try{
        List fileItems = upload.parseRequest(req);
        // assume we know there are two files. The first file is a small
        // text file, the second is unknown and is written to a file on
        // the server
        Iterator iter = fileItems.iterator();

//  正则匹配,过滤路径取文件名
     String regExp=".+\\\\(.+)$";

//  过滤掉的文件类型
  String[] errorType={".exe",".com",".cgi",".asp"};
     Pattern p = Pattern.compile(regExp);
        while (iter.hasNext()) {
         FileItem item = (FileItem)iter.next();
         //忽略其他不是文件域的所有表单信息
         if (!item.isFormField()) {
             String name = item.getName();
             long size = item.getSize();
             if((name==null||name.equals("")) && size==0)
                 continue;
          Matcher m = p.matcher(name);
         boolean result = m.find();
         if (result){
             for (int temp=0;temp<errorType.length;temp++){
             if (m.group(1).endsWith(errorType[temp])){
                   throw new IOException(name+": wrong type");
             }
             }
             try{

//        保存上传的文件到指定的目录

//        在下文中上传文件至数据库时,将对这里改写
                     item.write(new File("d:\\" + m.group(1)));

                   out.print(name+"&nbsp;&nbsp;"+size+"<br>");
                   }
                   catch(Exception e){
                     out.println(e);
                   }

                }
               else
               {
                 throw new IOException("fail to upload");
               }
               }
           }
        }
         catch (IOException e){
           out.println(e);
         }
         catch (FileUploadException e){
              out.println(e);
         }

//  保存上传的文件到指定的目录

//  在下文中上传文件至数据库时,将对这里改写

    }


 /**
  * Initialization of the servlet. <br>
  *
  * @throws ServletException if an error occure
  */
 public void init() throws ServletException {
  // Put your code here
 }

}
对应的请求文件:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>index.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">

    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>

  <body>
   <form action="./servlet/FileUpload" method="post" enctype="multipart/form-data" name="form1">
  <input type="file" name="file">
  <input type="submit" name="Submit" value="upload">
</form>
   <form action="./servlet/HelloWord" method="post">
    <input type="submit"/>
    </form>
    <form name="uploadform" method="POST" action="./servlet/FileUpload" ENCTYPE="multipart/form-data">

        <table border="1" width="450" cellpadding="4" cellspacing="2" bordercolor="#9BD7FF">

        <tr><td width="100%" colspan="2">

                        文件1:<input name="x" size="40" type="file">

        </td></tr>

        <tr><td width="100%" colspan="2">

                        文件2:<input name="y" size="40" type="file">

        </td></tr>

        <tr><td width="100%" colspan="2">

                        文件3:<input name="z" size="40" type="file">

        </td></tr>

        </table>

        <br/><br/>

        <table>

        <tr><td align="center"><input name="upload" type="submit" value="开始上传"/></td></tr>

       </table>

</form>

  </body>
</html>
注:该代码由部分来自网上!


相关文章
 
第 1 张,共 5 张