Insert data into two database without lose data.

Discussion in 'PHP' started by mohajer, Jun 4, 2008.

  1. #1
    Hi ,
    I have two database with MyIsam Engine :
    db1 : usersys1
    db2 : usersys2

    when user register on my site i will Insert all user info to both db separately in last register step.
    how it possible to be sure we will don't miss one of this Inserts ? (for example db1 ok , db2 insert failure due to anything)

    I need to insert all data to both database %100.

    for example maybe one of databases have problem or user connection closed
    before full insert.
     
    mohajer, Jun 4, 2008 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    
    $query = 'MYSQL_QUERY';
    
    $first_data = mysql_query($query, data1);
    if($first_data){
         $second_data = mysql_query($query, data2);
         if($second_data){ echo 'inserted both';}else{ echo 'unable to insert to second one';}
    } else {
         echo 'unable to insert to both databases.';
    }
    
    
    PHP:
    Peace,
     
    Barti1987, Jun 4, 2008 IP
  3. mohajer

    mohajer Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    maybe db2 result is failure , can we use rollback or such things for db1 ?
    can we use commit in mysql 5 for MyIsam engine? if yes , how to use?
     
    mohajer, Jun 4, 2008 IP
  4. alecs

    alecs Well-Known Member

    Messages:
    156
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #4
    alecs, Jun 4, 2008 IP