<?php

class Runner
{
  var $Name;
  var $Gender;
  var $Team;
  var $ChipNumber;

  function AddIfNotExist()
  {
    $DbResult = $this->Database->select('Runner', '*',
      '(`Name` = "'.$this->Database->real_escape_string($this->Name).'")');
    if ($DbResult->num_rows == 0)
    {
      $this->Database->insert('Runner', array(
        'Name' => $this->Name,
        'Gender' => $this->Gender,
        'Team' => $this->Team,
        'ChipNumber' => $this->ChipNumber,
      ));
      $Result = 1;
      $this->Id = $this->Database->insert_id;
    } else {
      $Result = 0;
      $DbRow = $DbResult->fetch_assoc();
      $this->Id = $DbRow['Id'];
    }
    return($Result);
  }
}
