Thursday, December 6, 2012

Exporting HTML table into CSV file

I work as a team member in a web application developer at my company. Often, I receive requests from the business users or (sometimes) auditors which asks me to generate some data (usually in CSV format) from the production database. Do not ask about the ACL or Picalo, they are not familiar with it :-(

In fact, actually,  those data which they needed already have provided in a report on the (web) application, but hey,...  they need raw data for further processing, for example in spreadsheet, and that's fine for them as business owners.

To reduce their dependence on programmers just to generate the data, as well as programmers reduced access to the production database (you know, it's a bad bad idea), we can use a Mozilla Firefox add-ons named ExportToCSV created by Souvik Chatterjee. This is a simple extension for exporting HTML table data as a CSV file

  • Just go to this page, click the 'Add to Firefox' button, follow the instruction, you'll need to restart your Firefox.
  • Next, select the menu Tools> Export to CSV> Settings
  • Give a tick on Include Texts from all nodes, and check on Ignore Line Breaks

  • Simple, just right click on any HTML table, on the context menu choose Export Data as CSV.
  • On the next dialog, select the location where you will save the CSV file. Anyway don't forget to give the extension. 'CSV' end of the file name (I think Mr.Souvik miss about this).
  • Click Save button

CSV stands for Comma Separated Values. In short, CSV is actually plain text file that contains values ​​separated by commas.

See the following picture, when i opened the CSV file in text editor :

Well, if the CSV file is opened with spreadsheet applications (eg Microsoft Excel), then they may look a little messed up as follows:

  • Simple. We can use the Text to Columns feature from Excel itself.
  • Highlight the cells  that are in the first column. 

  • Select the Data tab, then press the Text to Columns button.
  • The dialog wizard will appear;
  • In Step 1 gave tick on Delimited option, then press Next.

  • At Step 2, Set Delimiter to Comma, and Text Qualifier as ", then click Finish button

  • Hoopla! Your data will be neatly separated between cells. Furthermore, the data that data can be  processed through spreadsheet or Save as into Excel format.

Have a try. Not all reports must be requested from the programmer right? Anyway, programmers are human too,   :-)

Note, in this test I use :
  • Mozilla Firefox 14.0.1
  • ExportToCSV 1.2.b1 
  • Microsoft Excel 2007

Saturday, November 3, 2012


Got this from 9gag :-)

How to install SHC on your Linux system

SHC stands for Generic shell script compiler. Created by Francisco Javier Rosales GarcĂ­a, shc creates a stripped binary executable version of the script specified with -f on the command line. The binary version will get a .x extension appended and will usually be a bit larger in size than the original ascii code. Generated C source code is saved in a file with the extension .x.c .

In a simple word, SHC compile your Bash script into binary so no one can see your code. 

And here's step by step how to install SHC (I use Ubuntu 12.04 LTS) :

1. Download the latest version of SHC at here 

2. Put the package at your home (~) directory

3. Extract the tarball :

adee@thinkpad:~$ tar -xzvf shc-3.8.9.tgz 

4. Step inside into the shc folder and do the 'make' command :

adee@thinkpad:~$ cd shc-3.8.9/
adee@thinkpad:~/shc-3.8.9$ make
make: *** No rule to make target `shc.c', needed by `shc'.  Stop.

5. As you see above, there's an error about missing file named 'shc.c' Actually the 'shc.c' is already there, we just have to rename  / duplicate it into the right name :

adee@thinkpad:~/shc-3.8.9$ cp shc-3.8.9.c shc.c
adee@thinkpad:~/shc-3.8.9$ make
cc -Wall  shc.c -o shc
*** �Do you want to probe shc with a test script?
*** Please try... make test

6. Ok, then we shall continue to 'make install' command (need sudo):

adee@thinkpad:~/shc-3.8.9$ sudo make install
*** Installing shc and shc.1 on /usr/local
*** �Do you want to continue? y
install -c -s shc /usr/local/bin/
install -c -m 644 shc.1 /usr/local/man/man1/
install: target `/usr/local/man/man1/' is not a directory: No such file or directory
make: *** [install] Error 

7. Something sucks occurs again. It's looks like there's no such directory named '/usr/local/man/man1/'. So what should we do? Simple, just create that folder and repeat again the make install command. It should works now!

adee@thinkpad:~/shc-3.8.9$ sudo mkdir /usr/local/man/man1
adee@thinkpad:~/shc-3.8.9$ sudo make install
*** Installing shc and shc.1 on /usr/local
*** �Do you want to continue? y
install -c -s shc /usr/local/bin/
install -c -m 644 shc.1 /usr/local/man/man1/

8. Next, we have to move the shc binary file into /bin and give it the excecutable bit :

adee@thinkpad:~/shc-3.8.9$ sudo cp shc /bin/shc
adee@thinkpad:~/shc-3.8.9$ sudo chmod +x /bin/shc

9. OK Done! SHC is installed into your system. To test it, try type 'shc' at the terminal, and it should looks like this :

adee@thinkpad:~/shc-3.8.9$ shc 
shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script

OK on the next few days, i will write an article about the usage of SHC. So stay tuned :-)

How to shows subtitle (*.srt) in Windows 7 - Windows Media Player 12

By default, Windows 7 Windows Media Player 12 (WMP12) does not support *. SRT files for movie ssubtitles. To shows subtitle on WMP12, we can use Local Subtitles for WMP plug-in from This Plug-In will allow you to play movies with subtitles in Windows 7 Media Player 12

And here's the steps :
  • Prepare your video files
  • Download subtitle (*. SRT) in accordance with the title of the movies and languages you want. (Subscene is a recommended site for subtitle's searching).
  • Rename the SRT file name with the same name of your movie file (excluding the extension). 
For example:
- myvideodvdrip.mp4

    • The movie will be played. Make sure the subtitle is loaded by right clicking on the movie screen > Lyrics, captions and subtitles> On, if available
    • Done. Your WMP12 will shows the subtile below the the screen.

    Have a try ! :-)

    Saturday, October 27, 2012

    Extends your notebook battery's life with Aerofoil

    Aerofoil is an application that can help you to enhance your notebook battery life by disabling Aero and some configurations that sucking your battery power. This application is very useful for those of you who use notebooks and away from the power source (wall outlet) and also for those of you who have a notebook with a small capacity battery power. Besides the way to turn off Aero Glass, Aerofoil also disable some setting that has  potential to suck up your battery power.

     If you stick to wall outlet, Aerofoil will automatically set your power plan to "High Performance" which is included:
    • Enable Aero Glass
    • Enable Sound
    • Enable Sidebar 
    Meanwhile, if you are runs on battery, Aerofoil will turn your power plan to "Power Saver" which is included:
    • Disable Aero Glass
    • Disable Sound (mute)
    • Disable Sidebar 
    This application is open-source, free, and, oh...  it only runs on Windows Vista and 7, both 32-bit and 64-bit. This is a must have tiny app for your  notebook, go get it at

    PHP : Switch statement with multiple cases

    In PHP programming, sometimes we encounter in a conditions which we have to make a switch statement with multiple case values​​. Previously I was very confused how to make it, but after a bit of experimenting and googling anywhere, I finally find the way. See the code below for more details:
    # PHP    : switch with multiple case
    # Author :
    echo "| X | Y | ";
    echo "--------- ";
    for ($x=1;$x<=5;$x++)
      switch ($x) 
       case 1 :
       case 4 : $y = 'A';
       case 2 :
       case 5 : $y = 'B';
       case 3 : $y = 'C';
     echo "| $x | $y | ";
    and the result will be :
    | X | Y |
    | 1 | A |
    | 2 | B |
    | 3 | C |
    | 4 | A |
    | 5 | B |

    Thursday, October 25, 2012

    MySQL : case sensitive string comparisons

    If you want to do a case-sensitive string comparison in MySQL query, you can use the BINARY operator in its query.

    Furthermore,  see the screenshot below:

    Thursday, October 18, 2012

    How to Install Rar / Unrar on CentOS 6.2

    CentOS 6.2 comes with no rar / unrar support by default. Here's how to install Rar / Unrar support to CentOS 6.2 (login as root at first) :

    For CentOS 32 bit : 
    Install rar : 
    #rpm -Uvh rar-3.8.0-1.el6.rf.i686.rpm

    Install unrar : 
    #rpm -Uvh unrar-4.0.7-1.el6.rf.i686.rpm

    For CentOS 64 bit : 
    Install rar : 
    #rpm -Uvh rar-3.8.0-1.el6.rf.x86_64.rpm

    Install unrar : 
    #rpm -Uvh unrar-4.0.7-1.el6.rf.x86_64.rpm

    Wednesday, August 1, 2012

    Grub Customizer : Set default OS and customize your GRUB looks

    I use both Windows 7 and Ubuntu (dual-boot) on my ThinkPad. Since Ubuntu using Unity, I started back to using Windows 7 as my primary OS :-(

    The problem is at boot time, Ubuntu was take place as the default OS on the list and I have to always move the cursor to Windows 7 entry. And to be honest I never like the purple background on  GRUB.

    To customize your GRUB to look more personal, tidy, and set the default OS to Windows 7, here I give you a simple tips to change it:

    • Boot into your Ubuntu OS (I use Ubuntu LTS 12:04 - 64 bit)

    • Open a terminal, then install Grub Customizer with the following command:
    sudo add-apt-repository ppa:danielrichter2007/grub-customizer
    sudo apt-get update
    sudo apt-get install grub-customizer

    • Run Grub Customizer (you need to enter your administrator password here)
    •  In the appeared list, uncheck the entries that you do not want to be displayed. 

    • Click the Preferences toolbar, the Settings dialog will shows up
    • On the General tab, line Default Entry, select the OS Windows 7 on the dropdown menu
    • Move to the Appearance tab, you can customize the GRUB screen like color and font type, and can put a background image

    •  Close and Save. Please reboot, and you'll get a more personalized GRUB screen, neat and of course the default OS option on Windows 7
    Do have a try, and show me your GRUB :-)

    Thanx for Daniel Richter for making this great tool

    Sunday, July 29, 2012

    Cannot move large files into portable / external hard-drive

    Yesterday, I found that my friend-at-work (Mr.Danan) who confused because he couldn't move some large files (>8GB) to his new 500Gib external hard drive.

    He asked  for my help to solve this problem. And here's the following troubleshooting steps that I did.

    If you face same problems, you can try from first step. Once it solved, so there's no need to continue the next step.

    1. Make sure that the hard drive is not damaged:

    Do a check from Disk Management, make sure the hard drive in a healthy state. Also, you can use the CHKDSK /F command for fix some errors. Considering the hard drive was newly purchased, I believe that hardware damage isn't the issue here. So I go to the step-2

    2. Make sure that its file system is not FAT32:

    FAT32 has a problem in dealing with file sizes > 4GB. We must use the NTFS file system to enabling store large files. Furthermore about FAT file system and it's disadvantages, you can read from this link. You must format the drive into NTFS file system, of course after you've done data backup processfirst .

    Format a drive with NTFS file system

    But, in my case, I encountered that the file system drive had actually been with the NTFS format. So I'll go to the step-3

    3. Make sure you have installed the necessary drivers:

    Several type of external hard drive includes a special driver to run properly (usually a driver CD was included in the package). Also, it should be ascertained whether all the existing drivers on your computer (such as the chipset drivers, BIOS controller) is already installed and up to date. Please check the manufacturer's website and enter the type of equipment you have to get their driver. Updating the BIOS is also a suggested workaround.

    But still, in case I face, my friend does not have a problem in the drivers and all drivers are in a state up to date. So I'll go to the step-4

    4. Make sure the write-caching is enabled on the drive

    Go to the Device Manager, select the Disk Drives, right click on the external hard disk drive, select Properties. On the Policies tab, we can see if the write caching option (Better Performance) was in the can right on the drive.

    Enabling write caching

    And that solved the problem! Now my friend can copy-paste his huge data into the portable hard-drive.
    So what the hell is write-caching ?
    Write caching in a connected storage device refers to the use of high-speed volatile memory to collect write commands sent to data storage devices and cache them until the slower storage media (either physical hard disks or low cost flash memory) can accommodate them. Most devices that use write caching require that power be supplied continuously. (source link)
     Got the same problem? result may vary, share your tricks here...

    Friday, July 27, 2012

    Shutdown several services / application in batches with Taskkill

    I were stucked in these following situations :
    1. I have a notebook with some internet's bandwidth-hungry applications installed, such as Dropbox, Evernote, TeamViewer, Google Drive, uTorrent, FDM, and so forth.
    2. I were greatly helped by that apps above and do not want to get rid of them from my notebook
    3. Sometimes I need to shut down applications above one by one, especially when I run out of battery or out of quota internet :-)
    4. And that's the suckest point.
    To overcome it, here we can use the Windows  native command 'taskkill' , and to execute it in batches, then we must write it into a batch script.

    First, you must know the names of the service / image name you want to turn off. It can be seen from the Task Manager> Processes

    Second, the syntax we will use here are:
    taskkill / f / im [image_name_or_service_name]

    /f = forcely shutdown
    /im = image name

    For a sample, you can turn off the dropbox service by this command :
    taskkill / f / im dropbox.exe

    very simple isn't it ? Now open Notepad and write down following lines depend on what application that you want to shut down its service.

    Third, Save the file on the Desktop with file names ending in *. Bat (example : taskkill.bat)

    Fourth, and you're done. Whenever you want to stop those applications, simply double click on the batch file, and your unused apps will be shutdown immediately.

    Batch scripting can be fun! Learn more at :

    Monday, June 4, 2012

    Samsung Galaxy Ace : RAMDUMP ARM9 Mode Problem

    This morning i've got a strange error on my Samsung Galaxy Ace's (SGA) screen during it's boot. It shows up a blank black screen with a text "RAMDUMP Mode (ARM 9 Mode)". I have looking for some sources in Google on how to solve this problem. Many people are advised to do the hard reset / factory reset as pressing the Volume Up and Power simultaneously. There are also some people who suggest to press Home + Power button + Volume Up.

    But all these suggestions did not provide a solution to me. So what I did? I just pulled out the SD-card from its slot, then turn the device by pressing the Power button's on. Done! it solved my problem! SGA will boot properly, and after the Android home screen look good, you can safely insert the SD Card into it's slot.

    Have a try, and give me your feedback

    Sunday, May 20, 2012

    Installing Huawei EM660 on ThinkPad X100e

    Several months ago, i've bought a Mini PCI 3G Module, branded as  HUAWEI EM660 CDMA2000 for my Lenovo ThinkPad X100e.

    Previously  I knew that there is a single empty slot on the notebook's mainboard for a Mini PCI module. And also, actually  I  want to free-up one USB port rather than using an all-day-long attached 3G USB modem's dongle.

    I bought it from Jakartanotebook,  it was costs about $16 at the time.

    Specifications :
    The specifications of this modem are as follows :
    Features Description
    Product title EM660
    Dimensions:  Target:51mm×30mm×5mm
    Weight <30g
    External interface Compliant to PCI-SIG PCI Express Mini Card version 1.2(Support USB 2.0 protocol)
    Technical Standard CDMA 2000 1XRTT ;
    Compatible to CDMA IS-95 A/B 800/1900MHz;
    CDMA 2000 1x EVDO Rev.0 800/1900 MHz;
    CDMA 2000 1x EVDO Rev.A 800/1900 MHz;
    Operating Frequency CDMA/EVDO 800M
    CDMA/EVDO 1900M
    Data Rate EVDO Rev.A data service of up to DL 3.1 Mbps/UL 1.8Mbps
    Max. transmitter power CDMA 800 MHz :+23 dBm(Power Class 3);
    CDMA 1900 MHz +23 dBm(Power Class 2);
    Maximum power consumption Average power consumption <= 3.6W
    Power supply 3.3V/1100mA
    AT command Sets support 3GPP 27007 AT commands, and some Huawei defined commands.
    RUIM support RUIM,standard 6 PIN UIM card interface,support 3V and 1.8V UIM card
    Receive Diversity 800/1900Mhz receive diversity
    Antenna interface Use Hirose U.FL-R-SMT connector
    driver Supporting Windows 2000 、Windows XP、Vista and Linux(2.6.18 later)
    Operating Temperature -10 to 55° C
    Storage Temperature -20 to 70° C
    Humidity 5%~ 95%
    OS Support Supporting Windows 2000 、Windows XP、Vista and Linux(2.6.18 later)
    SMS service Supporting SMS based on CDMA 1x
    Language English ( can be customized)
    * taken from

    Installation :
    To install this module on the notebook is quite easy. I opened the bottom of the laptop (unscrew). The Mini PCI's slot is quite easy to find, it located next to the SIM Card slot.

    Plug the modem module carefully, lock it with (two) screws. There are two cables from notebook, each color Blue and Red. Now connect the blue cable connector to the antenna port labeled "A" (mean Auxiliary) and the red wire to the antenna port labeled "M" (mean Main). Do a gentle tap to make sure the connector is attached closely. And lastly, I do inserting the SIM card into its slot.

    Test Drive :

    This modem does not require special treatment. And it was immediately recognized as Huawei E169/E620/E800 HSDPA Modem by Linux (Ubuntu) without installing any drivers.

    On Microsoft Windows XP / 7, this modem is also 100% compatible with Mobile Partner application from Huawei.

    So how about the speed?. Well the modem is pretty stable and fast, and a little to warm if you're on a high load (such as downloading or watching youtube), of course without buffering :-)

    And this is the result of this modem with AHA (CDMA, from Bakrie Telecom) card (4GB Unlimited Plan, bandwidth 600kbps)

    At last, no more USB dongle attached :-)

    Ms.Office 2007 runs on Wine: how to solve blinking Office button problems (freezing Office)

    Although I use Ubuntu everyday at work, for reasons of compatibility to the other users I'm using Microsoft Office 2007 rather than LibreOffice.

    After I successfully installed Ms.Office 2007 on Wine with the help of PlayOnLinux (how? do read here), I started to  run Ms.Excel first.

    But what happened? Ms.Excel stopped working (freezing) with the splash screen stay appeared, with the anomaly that the Office at the top left keep flashing and blinking on.

    From my  observation, Ms.Excel in fact do a request for a user's Full Name and Initial information because this is a fresh install. And on unknown cause, the dialog box is closed by the modal windows of the splash screen :-(

    Well the solution is easy, press the key combination Alt + Space on the keyboard. A dropdown menu will appears, select Move, then press the arrow keys until the dialog box appear. Enter the requested informations, then press OK. Done!

    Press Alt + Space to show up the menu, then choose Move

    Move down the box with keyboard, fill the informations

    Hope you are helped by these tips.

    Note :

    Wednesday, May 16, 2012

    Ubuntu 12.04 : How to enable automatic login

    I know that automatic login feature (either on Windows or Linux) is a very-very bad idea. But sometimes this feature is still needed, especially for computers that are used for public area and do not have confidential data.

    On Ubuntu, you can switch on the feature easily. Open up the HUD, type 'setting' then choose the appeared System Setting icon. Next, choose the User Accounts module, unlocked it first, then slide the Automatic login switch to ON.

    Now, you can test it by reboot it once, and Ubuntu won't ask you for password to login.

    Thursday, May 3, 2012

    How to fix slow & choppy video playback on VLC

    There's nothing more enjoyable than watching high definition movies in 720p or 1080p resolution. For watching them, I always use VLC. Love this app, it is so powerfull, lightweight, free and compact.

    But for watching HD movies (720p and 1080p),  I got some slow & choppy experiences when playing them. Well, i've got some tricks to solve that.

    But first of all, make sure you've installed the latest driver for your graphic card. Please refer to your grapchic card's manufacturer website for latest driver.

    Well, this  little trick can solving the choppy playback problem, (at least for me) Follow several customization below on your VLC's Preferences : (Ctrl + P)

    uncheck Enable OSD & show media title

    check the Use GPU accelerated .. checkbox, Set Skip H.264 to 'All'

    well, I'm still experimenting with other settings. But at least with the above settings you should be able to improve the performance of your VLC's playback

    HD Videos plays nicely without choppy experiences

    Have a try and tell me what you've got

    This trick has been tested on VLC running on Ubuntu 12.04 and Windows 7
    on my ThinkPad X100e (ATI Radeon HD 3200)

    Tuesday, May 1, 2012

    Ubuntu 12.04 : How to make your Ubuntu looks spacious, neat, and clean as Windows XP

    One of the many things I hate about Ubuntu is the huge characters on its UI. It's make a narrow and crowded experiences when you use Ubuntu on a tiny display netbook. Apparently we can solve this by shrinking the text size into small size through the Universal Access menu.

    This simple trick give a major impact on the overall look of Ubuntu. Ubuntu UI look more spacious, neat, and clean. Almost similar to Windows XP. Just take a look at the comparison below :

    Thanks to Mr.Kamil Hayazidie (twitter : @milkajuicer) for this simple trick :-)

    Monday, April 30, 2012

    Face-Recognition logon with KeyLemon

    After I was disappointed because I couldn't install the Lenovo's face recognition applications, Veriface on my ThinkPad , then I tried to find a replacement of Veriface-like applications on the web. After a few browsing, I found an application called KeyLemon

    KeyLemon replaces the standard Windows logon and session lock-out with a face recognition dialog using a standard webcam. This application has the functionality and operations similar to Veriface. The installation is quite easy, we only need to complete four steps of it.

    Step 1 : Choose your webcam

    Step 2 : Take the correct position of your face

    Step 3 : adapt your face

    Step 4 : Enter your Windows password

    So how about the experience?
    Well, I think this application could be used to do some show off to your friends/mate. But for security reasons, I think the KeyLemon is less accurate and can be easily bypassed. Or maybe because I use the free version of KeyLemon where recognition accuracy level was locked to the medium. Perhaps..perhaps....

    It seems there's a lot of nice features if we upgrading the licenses. But, you know, I'm still looking for similar applications that are open-source :-)

    Interesting ?  You can try and download KeyLemon from here (CNET)

    Sunday, April 29, 2012

    How to make your self-made Dead-Pixels Detector

    If you are a person who always dealing with LCD, either a PC monitor or notebook monitor, whether you are a computer technician, (2nd-handed) electronic trading, or an electronic appraiser at a pawn shop, then you will be faced to do some checks for dead pixel on the LCD, to make sure the LCD that you're receive is in good conditions.

    So what the hell is dead (or defective) pixels? Defective pixels are pixels on a liquid crystal display (LCD) That are not performing as expected. Of Those, never a dead pixel, light shows, and a stuck pixel always shows light (typically red, blue or green), when the device is active. (Wikipedia)

    Dead-pixel(s) on LCD - pictures from Wikipedia

    So how do we check them ?. Instead of buying or installing special software, we can actually make our self-made Dead-Pixels tester tool with Microsoft Powerpoint.

    Do the following task :

    A. Create a presentation contains 8 slides with background color in  RGB + CMYK + White :
    • Wait a minute,.. what is RGB and CMYK stands for?  okay, here's RGB stands for : RED, GREEN, BLUE and then CMYK stands for CYAN, MAGENTA, YELLOW, BLACK. Furthermore for what is RGB and CMYK, you can read it at Wikipedia at here and here.
    • Create a blank presentation with Ms. Powerpoint (I use Ms.Powerpoint 2007)
    • On the first slide, right click on the slide, choose Format Background menu
    • Select Solid Fill, and select the RED color, and ensure transparency is at the level of 0%.
    • Click the Close button
    • Repeat the steps above with creating a new slide, and continue with the RGB,  CMYK, and White colors on slide background

    8 slides of RGB + CMYK + white

     B. Determine the resolution of your monitor :
    • Still in the Powerpoint 2007, on the Design tab, select the Page Setup
    • Select the appropriate ratio with typical kind of  LCD you use, whether in the form 'square' (ratio 4:3) or Wide-Screen (16:9 ratio)
    • Save by pressing the OK button
    Choose 4:3 or 16:9

    C. Save as PowerPoint Show for later use :
    • Save type presentation with Powerpoint Show (*. ppsx or *. pps), which later can be directly executed as executable files and without installation.
    D. Implementations : 
    • Clean your LCD screen with an electronic-safe cleaning fluid (I use Mr.Muscle Clear for Electronics from Johnson)
    • Run the *. ppsx file that we've just created above.
    • In every color, check carefully on your screen if there is black or white dots. If it exists, then the LCD is likely to have dead-pixel.
    • Continue checking until the presentation is completed.
    • Keep in mind, this methods only to examine the dead-pixel on the LCD, rather than fix it.
    My ThinkPad on scanning

     Hope this article is useful,

    And if you're too lazy to make it your own self-made presentation detector, here I've share mine for free downloads :

    Missing 'clear' command in Cygwin

    Are you a Cygwin user and do you lose the 'clear' command  to clear up your screen just as we found in the Linux terminal?

    Well, here's the solution. Just re-run the setup again. In the Select Packages'
    dialog , add an application named 'ncurses'

    Done! from now on, the 'clear' command is available on your Cygwin!

    Saturday, March 17, 2012

    PHP : How to import DBF table into MySQL database

    I am currently working on a web project where requires a feature to import the DBF's table(s) into MySQL database.

    After some experiments, i found a powerful PHP class named 'dbf_class' written by Mr. Faro K. Rasyid and with the help of Mr. Eko Wahyudiharto (thanx dude), I finally succeeded to create it.

    Basically, the process is fairly easy. As the DBF file uploaded, do a loop to read records line by line, and also doing the inserting into MySQL database.

    Here's the script (on PHP) (of course, download the dbf_class first, i put it at /lib directory) :

    The script for index.php :
    <title>Mulia Web</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <h2>Upload File DBF</h2>
    <form action="upload.php" method="post" enctype="multipart/form-data" name="file_upload_form" id="file_upload_form">
    <input type="file" name="filenya">
    <input type="submit" name="X" value="Submit">
    <iframe id="upload_target" name="upload_target" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>

    And here's the script for upload.php
    define("DB_HOST", "localhost");
    define("DB_USER", "root");
    define("DB_PASS", "123456");
    define("DB_NAME", "muliaweb");
    mysql_query("SET time_zone='Asia/Jakarta'");
    if (isset($_POST['X']))
    if ($_FILES['filenya']['size']>150000)
        echo "<script>alert('File tidak boleh melebihi 150Kb')</script>";
        $thefile = '';
        $name = $_FILES['filenya']['name'];
        if (move_uploaded_file($_FILES['filenya']['tmp_name'],"dbf/$name")) $thefile = 'dbf/'.$name;
        $timer = new timerClass();
        $timer ->start();
        $dbf = new dbf_class($dir.$thefile);
        $endexct = $timer->end();
        for($i=0; $i<$num_rec; $i++)
            if ($row = $dbf->getRow($i))
                for($j=0; $j<$field_num; $j++)
                    if ($dbf->dbf_names[$j]['type']=='N')
                        $perintah = $perintah . $row[$j] . ",";
                    else if ($dbf->dbf_names[$j]['type']=='C')
                        $perintah = $perintah . "'" . $row[$j] . "',";
                    else if ($dbf->dbf_names[$j]['type']=='D')
                        $perintah = $perintah . "date('" . $row[$j] . "'),";
                    $pjg_query= strlen($perintah);
                    $perintah = "INSERT INTO temp_order VALUES (" . substr($perintah, 0, $pjg_query-1) . ")";
                    $hasil=mysql_query($perintah) or die ("<script>alert('data doble!')</script>");

    The next stage, is how to export database from MySQL to the DBF. So stay tuned, I 'll be right back!