Minggu, Januari 08, 2012

MySQL : mysqldump with -w option on Windows XP

Case : You have a big size of mysql database table on windows xp machine and you want to dump database table with "where" condition
Solution : using -w option

set_time_limit(0);

$username = "root";
$password = "toor";
$hostname = "localhost";
$sConnString = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");

$connection = mysql_select_db("Country",$sConnString)
 or die("Could not select DB");

$sql = "select * from tblkelurahan where left(KelurahanID,4)='3277'";
$query = mysql_query($sql);

while ($fetch = mysql_fetch_object($query)) {
 $namafile = $fetch->KelurahanID;
 $command = "C:xampp\\mysql\\bin\\mysqldump.exe --add-drop-table -uroot -ptoor -w\"KelurahanID='$namafile'\" Indonesia tblpenduduk > $namafile.sql";
 system($command);
}

Kamis, November 24, 2011

Javascript : Reload Target / Parent Window From Second Child Window

I have problem like this guy on this link.

Solution : use window.name, and target it to reload

On parent page :
window.name = "parent_window";

On the first child page :
function open2print(id_cek_in,diskon) {
 window.open( "cek_print.php?id_cek_in="+id_cek_in+"&cetak=y&diskon="+diskon, "print","status=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=600,height=800" )
}

On the second child page :
function reloadWin(){
 var parent_window = window.open("", "parent_window");
 parent_window.location.reload(true);
}

<body onload=reloadWin();>

So when the second child window load, it will be reload parent window.

Source : http://www.codingforums.com/showthread.php?t=113902


PS : I hate javascript, too many parents and children involved :(

Kamis, November 17, 2011

Bash : Auto Delete Old Backup Files

Based on my experience on maintenance project.
It's about to create auto delete old backup files on Mandriva 2005 (Linux) server.

This article is related with this article

After create backup file there will be alot of files created in our backup folder.
So we need an auto delete old backup files.

1. Create recycle.sh
$ mcedit /recycle.sh

File content :

#! /bin/sh
find /backup | grep `date -d '1 week ago' +%Y-%m-%d` | xargs --no-run-if-empty rm

2. Edit crontab

$ mcedit /etc/crontab

File Content :

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
00 15 * * 1-6 root /bin/sh /recycle.sh

3. Reconfigure your crontab

$ crontab -u[username] /etc/crontab
$ crontab -l

Auto delete scheduled every Monday through Friday 2 pm :)

Modified from : http://unix.stackexchange.com

Bash : Auto Backup Mysql on Mandriva 2005

Based on my experience on maintenance project.
It's about to create auto backup mysql on Mandriva 2005 (Linux) server.

1. Create file backup.sh, you may using mc or pico

$ mcedit /backup.sh

File content :

#! /bin/sh
/usr/bin/mysqldump -u[username] -p[password] [database_name] > /[your_backup_directory]/[filename].sql
cd /backup
tar --remove-files -czf backup-`date '+%Y-%m-%d' `.tar.gz -R *.sql
sudo cp -f *.tar.gz /[another_backup_directory]

2. Edit your cron list

$ mcedit /etc/crontab

File content :

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
00 7-14 * * 1-6 root /bin/sh /backup.sh

3. Reconfigure your crontab

$ crontab -u[username] /etc/crontab
$ crontab -l

MySQL auto backup scheduled every Monday through Friday beginning at 7 am till 2 pm :)

Senin, September 26, 2011

phpMyAdmin : How to Import Large CSV

Case : You have a big file size csv to import to mysql using phpmyadmin
Solution : Use mysql script instead of import form from phpmyadmin (that will save you a lot of time)
Script :
LOAD DATA LOCAL INFILE 'file_name.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(column1,column2,column3);


Note : place your csv file in your phpmyadmin directory

Source : http://www.phpfreaks.com/forums/index.php?topic=343906.0