Saturday, March 12, 2011

MySQL LOAD_FILE() in Ubuntu, It Works!

Recently, I want to create a php site that will display images retrieved from MySQL database. I always prefer to work with CLI mode other than using query browser for create databases, tables, updating etc.

LOAD_FILE can be used to store images into database through MySQL command line (client). I'm using MySQL version 5.1.41 on my Ubuntu 10.04. Here are the simple steps:

Step 1: Initially we will create a database and tables

mysql> create database testdb;

Query OK, 1 row affected (0.00 sec)
mysql> use testdb;
Database changed
mysql> create table myimages
-> (
-> id integer unsigned not null auto_increment,
-> name varchar(20),
-> type varchar(10),
-> picture mediumblob not null,
-> primary key (id),
-> unique (name)
-> );

Query OK, 0 rows affected (0.09 sec)
mysql> desc myimages;

Step 2: Upload an image
At first, I've tried to upload an image from a directory located at '/home/user1/Pictures/ubuntu_logo.jpg'.
mysql> insert into myimages (name, type, picture) values ('xyz', 'jpeg', LOAD_FILE('/home/user1/Pictures/ubuntu_logo.jpg'));

ERROR 1048 (23000): Column 'picture' cannot be null

This error occurred because the result of LOAD_FILE('/home/user1/Pictures/ubuntu_logo.jpg') has return the NULL value probably due to privileges and permission of the /home/user1 directory which is belongs to user1.
The same problem also has been brought up in mysql forum.
After checked on /etc/passwd, it shows that the mysql's home directory is located at /var/lib/mysql/, where permission is fully given for mysql user.
Simply login as root user and copy the image to /var/lib/mysql or you may created your own directory such as /var/lib/mysql/all_images
$ sudo su

$ mkdir /var/lib/mysql/all_images
$ cp /home/user1/Pictures/ubuntu_logo.jpg /var/lib/mysql/all_images

Now, try to run the same insert command again with different directory.
mysql> insert into myimages (name, type, picture) values ('bz', 'jpeg', LOAD_FILE('/var/lib/mysql/all_images/ubuntu_logo.jpg'));

Query OK, 1 row affected (0.00 sec)

Yeah, it works!!

Friday, December 31, 2010

Manisnya 2010 :)

Sedar atau pun tidak, tahun 2010 dah nak berakhir pun. Biasa aku takde kisah sangat, tapi bile pikir2 cam banyak lak kenangan 2010 ni..dan yang paling touching sekali, banyak kenagan2 tu di lalu bersama :)

Computer Science Final Year Project (FYP), IIUM
awal2 tahun ktorang da wat FYP bersama, Alhamdulillah topic yang ktorang pilih tu agak simple dan ade research value, "Performance Evaluation of Clustered Memcached".

Terima kasih kepada Dr. Mohiuddin yang banyak membantu dan guide kami tuk siap kan sampai hari presentation (dah la ktorang present 1st, gile gementar.. haha ) dan sebelum hantar untuk conference. Tak lupe jugak pada parents, kawan2 yang sesame wat FYP, sume da banyak bagi semangat and tolong mane yang patot.. terbaek lah.. hehe.. ^_^

Ni time final presentation..

Internship at MIMOS Berhad
Bile FYP selesai pada pertengahan tahun (malas aku nak ingat bulan bape.. hoho), kami pun bergegas mencari tempat tuk 6 bulan internship atau nama mesra nye 'practical'.. actually, banyak gak tempat ktorang apply.. erm, banyak gak ktorang dapat.. tapi nak wat camne, dapat tempat intern pun same.. hehehe.. seronok kan (xtau la korang camne, aku for sure happy.. haha) kitorang pun dapat kt Mimos, Bukit Jalil under Wireless and Communication Solution Cluster, 6LoWPAN group.

Kalau nak citer camne life kat sini, memang sampai bsok xhabis2.. hahaha.. Pendek kata,
- Supervisor and staff BEST!!!! Special thanks to Reza Khosdel, Zeldi, Gopi (examiner aku mase present FYP), Shariq, Abbdu, Moshi, Dr Mazlan, Kak Lina dan Mdm Normi.. dapat A tu, Alhamdulillah :)
- Geng Intern pun best, Abul, Kok Jin, Mint, Dayang, Chui and Fakrol
- dan last, ofkos la my partner.. sporting gilerrr woo.. hihi
- lupe lak, yang paling obvious aku naik 8 kilo kat sini, supervisor ktorang pun sebenarnya da macam mentor makanan.. Terbaek! Filosofi dia, "People who enjoy foods, will enjoy life" Ktorang salu makan kat Halfmoon, Pizza hut, MMU food court etc sume sodap2 belaka.. lapo pulak rasa.. :P

Supervisor ktorang, amacm?? hensem x? Reza Khosdel dan Zeldi Suryadi..

Geng intern (dayang, mint, ina, aku yg xbape nak nerd nidan kok jin)
minus abul, chui dan fakrol :)

ICT4M 2010 Conference, Jakarta

9 Dec 2010, 9.00 pm, Tiba di jakarta
Hoho.. nak ikot kan ni yang paling best bile kami dapat2 jalan Bandung dan Jakarta, shoping sakan kot. Tapi paling lame kat bandung la, 3 hari. Ada 1 hari tu, dekat 6 jam ktorang pusing 1 pasar baru tu.. dasyat2..hahaha

Pengalaman yang tak dapat dilupakan bile time conference, sume authors tu lecturer, master dan Phd.. tekezut aku.. tapi best sebab makanan bes.. hehe :D
Aku pun da malas tulis panjang2.. aku post je la.. hahaha..

Jalan2 di Bandung..

UIN, Jakarta: hepi nampak cik kak..haha

Selepas presentation.. lega rase nye.. hehe

Slide tuk present..

Summary: yang penting.. kerja sama :)

Tuesday, December 7, 2010

Salam Maal Hijrah

Bismillah..Azam tahun baru ..

Saturday, October 30, 2010


This is common problem in Windows XP that disallow user to boot onto XP. Probably there are files corrupted due to improper shutting down or power failure.

What i did to solve is, put on Windows XP CD and boot into CD mode. Then, wait until it will prompt with few options, like for installing fresh windows and repair. Choose option to repair by press 'r'.

Next step, you will see command line interface (CLI). It will show an option for partition (i.e C: or D: ). Just choose the number where you have installed the windows. In my case I press 1 for partition C. Then, it will ask for administrator password. If you did not set any password for admin, just leave it blank and press ENTER.

You will see like this.

Here, I run check disk instead of copying corrupted files.
C:\WINDOWS>chkdsk c: /P /R

Note that c: is the partition drive of the installed windows. See the manuals from run:
'chkdsk /?'

Then wait for about 30 minutes (according to size) until 100% completed. After finish type 'exit' to reboot

Thats all, hope it will solve yours =)

Wednesday, October 20, 2010

Time is Moving ..

Now i realize that i'm about to finish my 6-month internship and start a job at new company..hope everything will be always fine..amin :)

Wednesday, September 29, 2010

Monday, September 20, 2010

Windows Media Center VIRUS: what to do?

Last weekend my friend come to my house and bring his new laptop with new problem. All programs cannot be opened because registry is corrupted. I try to open any program, includes mozilla, yahoo messenger,cmd and regedit, but this crappy windows 7 always redirect to open Windows Media Center. All programs' icon turn to windows media center. I try to ask google and it is actually a virus. What we need is repair the registry that fooling windows user.

The solution is:

download this registry file HERE, and double click on it.

or copy paste these two lines into a file and save it file.reg. Then, double click it.

Windows Registry Editor Version 5.00

Then reboot to restore your icon as normal.
Hopefully this will help u :)