Programming

Just another WordPress.com weblog

การเก็บไฟล์ Binary (เช่น pdf, gif, jpg) ลงในฐานข้อมูล MYSQL

แสดงความเห็นโดย จั่น บน ตุลาคม 16, 2009

หากต้องการเก็บ ไฟล์ binary ลง field ที่มีคอลัมน์เป็น BLOB, MEDIUMBLOB หรือ Largeblob ก็ตาม   ใน 1 Insert statement ของ SQL  มักจะมีขนาดใหญ่ไปตามไฟล์ที่ต้องการจะใส่เข้ามา

สิ่งที่ต้องทำคือ default ของ mysql  จะตั้งให้ max_allowed_packet=1M

ดังนั้นจะต้องแก้ให้ใหญ่ขึ้นมาดังนี้

Way to increase your maximum allowed packet size in your MYSQL server

  • Open your my.ini file in the MYSQL server folder.
  • Add this entry max_allowed_packet = 32M beneath the [mysqld].
  • Now restart your MYSQL server

******วิธีการตรวจว่าตอนนี้ MYSQL ของเรามี  max_allowed_packet ก่อนและหลังปรับเท่าไหร่   ให้ใช้ mysql client ใน Command prompt

C:\mysql

mysql>mysqladmin -p variables

ใส่ความเห็น

XHTML: คุณสามารถใช้แท็กเหล่านี้ได้: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>