Exemple #1
0
 public function save()
 {
     $db = mysqli_connect(DBHOST, DBUSERNAME, DBPASSWORD);
     if (!$db) {
         print "\nUnable to save, cannot connect to the DB\n";
     }
     $rc = mysqli_selectdb(DBNAME);
     for ($i = 1; $i < Person::$theCount; $i++) {
         $person = Person::getById($i);
         $cameFromUnionId = 0;
         if ($person->cameFromUnion) {
             $cameFromUnionId = $person->cameFromUnion->id;
         }
         $sql = "INSERT INTO person (personId,name,realName,gender,dateOfBirth,dateOfDeath,cameFromUnionId,ordinal,suppress) VALUES (";
         $sql .= $person->id . ", '" . $person->name . "', '" . $person->realName . "', '" . $person->gender . "', '" . $person->dateOfBirth . "', '" . $person->dateOfDeath . "', " . $cameFromUnionId . ", " . $person->ordinal . ", " . $person->suppress . " ) ";
         $sql .= " ON DUPLICATE KEY UPDATE name='" . $person->name . "', cameFromUnionId= " . $cameFromUnionId;
         $rc = mysqli_query($sql);
         if (!$rc) {
             print "\n>>> error = " . mysqli_error() . " sql= " . $sql;
         }
         // save attributes
         foreach ($person->attribs as $attrName => $attrValue) {
             if (is_array($attrValue)) {
                 $tmp = join(",", $attrValue);
                 $attrValue = $tmp;
             }
             $sql = "INSERT INTO personattr (personId, attrName, attrValue ) VALUES (";
             $sql .= $person->id . ", '" . $attrName . "', '" . addslashes($attrValue) . "' );";
             $rc = mysqli_query($sql);
             if (!$rc) {
                 print "\n>>> error = " . mysqli_error() . " sql= " . $sql;
             }
         }
     }
     // save marriages
     for ($i = 1; $i < Marriage::$theCount; $i++) {
         $marriage = Marriage::getById($i);
         $sql = "INSERT INTO marriage (marriageId, personId1, personId2, suppress) VALUES ( ";
         $sql .= $marriage->id . ', ' . $marriage->personId1 . ', ' . $marriage->personId2 . ', ' . $marriage->suppress . ') ';
         $sql .= " ON DUPLICATE KEY UPDATE personId1 = " . $marriage->personId1 . ", personId2 = " . $marriage->personId2 . ", suppress=" . $marriage->suppress;
         $rc = mysqli_query($sql);
         if (!$rc) {
             print "\n>>> error = " . mysqli_error() . " sql=" . $sql;
         }
     }
     mysqli_close();
 }