Archive forApril, 2009

PhD resolutions

This is only for fun. Please don’t take it seriously.

Before joining PhD:
I want to win the Nobel Prize.
I want to win the Turing Award.

First year of PhD:
I want to finish PhD in two years.
I want to publish papers only in top tier conferences.
I want to make ground-breaking research..
I want to win the best PhD Thesis award..

Second year of PhD:
I want to finish PhD in 5 years.
I want a problem.
Shall I change my advisor?

Third year of PhD:
I want a paper; I don’t care which conference.
Shall I change my topic?
I want to be known as Dr bhOndOO.

Fourth year of PhD:
I want to finish PhD!
My industry-friends have two children by now. When will I get married?

Fifth year of PhD:
Why did I come here?
Why did I choose this advisor?
Why did I choose this topic?

Sixth year of PhD:
Someone give me a degree!
I want to leave this place [WINDOWS-1252?]— for ever..
Let me leave.

Seventh year of PhD:
People call me uncle.
She waited and finally married someone else.
I don’t want any degree. I just want to live peacefully.

Comments

MySQL database backup using PHP

Well, I went through a lot of articles with respect to the above mentioned topic, but I was unable to find one which I really wanted. Most of the articles informs you how to backup the data and send a mail to the user from where they can download the archived file.

My requirement was to download the archived file at the click of the button without sending a mail to the end user. The user should be able to download the file from the browser interface.

require('../config/config.php');
if($_GET["filename"]!="")
{
$filename=$_GET["filename"];
$handle = @fopen($filename, 'r');
if (!$handle) {
exit(0);
}
$time= date('Ymd');
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=psp-".$time.".zip");
while(!feof($handle) and (connection_status()==0)) {
print(fread($handle, 1024*8));
flush();
}
fclose($handle);
}
else
{
system("mysqldump -u $dbusername --password=$dbpasswd psp > /tmp/psp.sql");
system("cd /tmp;zip -r psp psp.sql >/dev/null");
header( "Location: http://$domainname/custom/mysqlbackup.php?filename=/tmp/psp.zip"););
}

`config.php` includes all the configuration parameters for connecting to the database. Since we are using a single file for posting, we check in the `url` whether the file name has been passed or not. In case the file name has been passed, we add headers to the content-type for download. You need change the download filename. As per my requirements I have used `psp` followed by the date when the download takes place.

I have used `mysqldump` for backing up the database. This is not an efficient way of taking a backup since the `username` and the `password` are sent across the network in plain text. Any user using a network sniffing tool can get hold of the `username` and the `password`. I preferred to use in this way as my script is not exposed to the internet. The last line indicates the reloading of the same page with the archived file name.

Comments