Exemple #1
0
 /**
  * @param string $statementName
  * @param string $sqlStatement
  * @return resource
  */
 public function prepare($statementName, $sqlStatement)
 {
     $paramCnt = 0;
     $pgStyleVar = '$' . ($paramCnt + 1);
     while (false !== strpos($sqlStatement, $pgStyleVar)) {
         $paramCnt++;
         $sqlStatement = str_replace($pgStyleVar, $this->varPrefix . chr(64 + $paramCnt), $sqlStatement);
         $pgStyleVar = '$' . ($paramCnt + 1);
         if ($paramCnt == 9) {
             // limited number of replaced place holders
             break;
         }
     }
     $sqlStatementWithoutPostgresKeyWord = str_replace(' ONLY ', ' ', $sqlStatement);
     $stmt = $this->dbConnection->prepare($sqlStatementWithoutPostgresKeyWord);
     $this->preparedStmt[$statementName] =& $stmt;
     return $stmt;
 }
Exemple #2
0
 public function __invoke()
 {
     $root = __DIR__ . '/..';
     $db = new Sqlite3($root . '/db/data.sqlite3', SQLITE3_OPEN_READWRITE);
     $openErr = $db->lastErrorCode();
     if ($openErr) {
         throw new Exception($db->lastErrorMsg());
     }
     $db->enableExceptions(true);
     $stmt = $db->prepare(self::QUERY_SOLDIERS_LIST);
     $result = $stmt->execute();
     /**
      * @var $soldierList Soldier[]
      */
     $soldierList = [];
     while ($record = $result->fetchArray(SQLITE3_ASSOC)) {
         $soldierIdentity = new SoldierIdentity($record['firstName'], $record['lastName'], $record['nickName'], $record['nationality']);
         $soliderServiceRecord = new SoldierServiceRecord($record['status'], $record['rank'], $record['specialization'], $record['numMissions'], $record['numKills'], $record['hp'], $record['will'], $record['defence'], $record['aim']);
         $soldierList[] = new Soldier($soldierIdentity, $soliderServiceRecord);
     }
     $this->response->setBody((new TemplateFactory([$root . '/tpl']))->loadTemplate('home.twig')->render(['soldierList' => $soldierList]));
 }