Main Content RSS FeedLatest Entry

How can I fetch data from one database on a server and store them in other database on another server using PHP?

Many times we need to transfer data from one database exists on a server to another database exists on another server ,in that case we can use fourth parameter of mysql_connect function which is an optional parameter. If fourth parameter is true then it will create a new link for another database connection even if we have created database connection earlier with same detail with same database or with another database. Lets discuss how it works by an example.
Function syntax:
mysql_connect ( [string $server [, string $username [, string $password [, bool $new_link [, int $client_flags]]]]] )

Now Connect database1 using host, username and password as given below
$db1 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(’db1name’, $db1);
Fire a query on db1
$res1 = mysql_query(”query”,$db1);

Connect database2 using host, username and password and include fourth parameter true as given below
$db2 = mysql_connect(”host”,”user”,”pwd”, true)
mysql_select_db(’db2name’, $db2);
Fire a query on db2
$res2 = mysql_query(”query”,$db2);

Now both link will remain live.If you will not use fourth parameter than setting of $db1 will be overwrite by $db2 so you can not use both objects without using this fourth parameter as true.Now after using fourth parameter you can use both database1 and database2 on same page.You can fetch data from first database and than insert that data in second database .

Recent Entries

javascript validation to check only one checkbox among multiple checkboxes

Suppose you have a page with the listing of all the users registered on your site. Every record has a check box with it to select that record . Client want that user can select only one record at a time from that list and user must select one record for further action. Now what to do . Don’t worry this is not so hard , you can found the solution on web for this or you can write your logic for this. But i am giving here so you can find it very easily.Here it is:
Read More..

javascript validation to check if two combo boxes has same value

Suppose you have a form with 5 different combo boxes and those combo boxes have same data. Now client want that you can not select same data in 2 combo boxes.Also you have to select all 5 combo boxes.
How to do this by javascript. ok let me show you these 2 functions. I made these 2 functions when i faced this problem in one of my website , now i am giving this to you. Have it and enjoy the programming.
Read More..

How to unzip a zip file using php

Very exciteing and challenging work!.You are thinking that what is exciteing and challenging in this work but i am talking about how to unzip a zip file using php.
Some times programmer has the requirment to select a zip file and unzip all the files and folder at a particular location and then delete that zip file.

I faced this problem first time when i was making a file manager in php . That was not just a file manger but also a full featured ftp client.I tried to search on
google but not found anything .finally i got a small help from google and than i made a good function for you all to unzip a zip file.
Read More..

how to download a file without display download request

Usually when we try to download something from a server we get a confirmation request whether you want to save the file or open it.
To avoid this request you can use the below code and then user can directly download that file without any message.

First give a link or a button for user to download and when they click redirect them to a file which will have the code below.

suppose you want user to download a pdf file then first make a link like this:

<a href=”javascript:void();” onClick=”location.href=’doc/document_download.php’”>download pdf</a>

Read More..