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!


Sunday, March 4, 2012

Problem on the Safely Remove USB drive: "The device can not be stopped right now" (locked by wmpnetwk.exe)

I use the Windows 7 Ultimate Edition 64-bit OS' on my ThinkPad, and i often encounter the intermittent problem every time I want to remove the USB drive safely. Sometimes it'll show a notification telling the drive / device can not be stopped, and also show the process which locked it named "wmpnetwk.exe "

So what the hell is wmpnetwk.exe? Please read here and here

This service will be required if you want to share media or stream it over the network using Windows Media Player. Since I am using VLC Player as my main media player, so it will have no effect to me.

Apparently this service is pretty much consuming resources on our computers:

There are two methods to solve this problem:

The first method:

  • Go to Control Panel >  Homegroup
  • Select option Leave the Homegroup
  • Now try to Safely Remove your USB drive. At least this method works for me :-)

The second method:
From what I've read on the internet, some people decide to permanently disable this service. To do this, do the following task :
  • In the Start Search enter the word "services.msc" (without the quotes) and then press ENTER
  • Look for a service named "Windows Media Player Network Service Sharing"
  • Click on the Stop the service

  •  Then double-click on the service, in the Startup Type dropdown select the option Manual and then click OK.

  • Restart your computer.
  • Done! The locked USB Drive's problem should not be happening again.

Saturday, March 3, 2012

Home sweet home with Sweet Home 3D

Sometime, it's quite confusing when we want to build a dream house, especially when we're tried to design the shape of the building. Plus if we're the kind of people who have a poor sense of art and not mastering AutoCAD. Complete, please contact your home architect and prepare some money :-(

Yes, that's what happened to me. But finally, i found a freeware called "Sweet Home 3D". With this application i can  represent what do I have in mind in designing the house up.

The application is pretty easy, just click and drag. You just need to make walls and rooms. For more advanced, you can try to be creative by incorporating ornaments such as bed, chair, TV, doors, windows and many more (available in the left panel)

Sweet Home 3D

To obtain a precision, you can change the unit's measurement to 'meter' by selecting File menu > Preferences > Units = Meters

Interestingly, you can review your work as well as Aerial View (from above) and as  Virtual Visit, as if you are in the house. So much fun!

3D Virtual Visit

From what we have done, the output can generated as *.sh3d,  ZIP,  PNG, PDF, and even in movie form.

So? Wanna try ? Download Sweet Home 3D from here or try it online.