If the primary key exist use an UPDATE tranzaction to rewrite all fields if not existing use INSERT:
$sql="SELECT id FROM table1 WHERE name='old_name'"; $result = mysql_query($sql); if (There_is_no_id){ $sql="INSERT INTO table1 VALUES (...)"; }else{ $sql="UPDATE table1 SET ... WHERE id='$id_from_db'"; } -- ------------------------------------------------- Cristian MARIN InterAKT Online (www.interakt.ro) +4021 411 2610 [EMAIL PROTECTED] "Toby z" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] good heavenz man lemme breath first ok > That sounds to be a strange approach to restore an back up. > What precisely are you trying to achieve? > > I assume you also are aware about that a backup mostly only saves > time points, and that you usually need to restore the latest full > back up and then add on incremental changes until the last time > point before you database did what ever nasty thing it did. backup goes on a user's request 1. the code fetches up data from about 39 tables where new_backup = 0 which meanz the data iz new and has never been backed up before 2. after the data s fetched the code updates all new_backup = 1 through out the 39 tables 3. a file is saved on the local disk (this waz the clients requirement they want the data to be backedup on local machines as the internet connections are horrid in most parts of the country where they ll be running the applicaiton n its to be restored by the administrator in the headoffice when he gets the file stored on a disk or sumthin) 4. the administrator then can retore the backup on the server he ll have to run the script file brought in (the backup file) creating a new dtabase on his server 4.i there are 9 prime key tables proj_unit(pu), union_council(uc), supervizor(sup), village(vill), community-health-worker(chw), family(fmly), mother(mo), child(chld), other-family-memberz(othr-fmly) 4.i.a : fetch pu's from backup db compare against pu in server db if match found get server db pu_ids replace backup-db pu_idz by servers else get max(pu_id) from server db inzert pu from backup db into server with its id==max(pu_id) from server db 4.ii: loop 4.i for all 9 tables 5. now all the prime key tables have unique values so i can move in to inzert the rest of the data from backup-db to server db n this is the problem all my primary keyz are auto-increments if i inzert the data as i picked it up from the local machine along with its primary-keyz i get an error for duplicate entries i guess the backup that i actually fetch otta be without these primary keyz but then i need the primery keys of the 9 prime tables what the fuck m i suppozed to do im sorry fo soundin freeked out but this thing is gonna b deployed in about 20 hours from now :'( can sum1 plz help > And by the way what kind of RDBMS are you trying to restore and > what kind of back up system are you using? mysql :) > //Anders > > > -----Original Message----- > > From: toby z [mailto:[EMAIL PROTECTED] > > Sent: Thursday, June 05, 2003 1:50 PM > > To: php hlp list > > Subject: [PHP-WIN] how do i skip primary keyz ???? > > > > > > hay guyz > > > > im a bit stuck > > im restoring backup data and i need to fetch all fields of tables > > except for the primary key > > is there anyway to do that ????? > > i ve been searchin fo a biultin function but couldnt find any > > > > im sorry if this is off the list .... :$ > > thnx a mill > > > > toby > > > > > > __________________________________________________ > > Yahoo! Plus - For a better Internet experience > > http://uk.promotions.yahoo.com/yplus/yoffer.html > > > > -- > > PHP Windows Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > __________________________________________________ Yahoo! Plus - For a better Internet experience http://uk.promotions.yahoo.com/yplus/yoffer.html