Exemplo n.º 1
0
 public function userExists($id)
 {
     //Check that the username is not present in the database
     $dbAdapter = $this->serviceManager->get('Zend\\Db\\Adapter\\Adapter');
     $validator = new \Zend\Validator\Db\RecordExists(array('table' => 'utilisateur', 'field' => 'id_utilisateur', 'adapter' => $dbAdapter));
     return $validator->isValid($id);
 }
Exemplo n.º 2
0
 /**
  * Insert the base data rows.
  */
 private function insert_rows()
 {
     $adapter = $this->adapter;
     $sql = new Sql($adapter);
     $validator = new \Zend\Validator\Db\RecordExists(array('table' => 'account', 'field' => 'username', 'adapter' => $adapter));
     $account_rows = array();
     if (!$validator->isValid('Administrator')) {
         array_push($account_rows, array('username' => 'Administrator', 'password' => md5('Administrator')));
     }
     if (!$validator->isValid('Staff')) {
         array_push($account_rows, array('username' => 'Staff', 'password' => md5('StaffStaffStaff')));
     }
     if (!empty($account_rows)) {
         $insert = $sql->insert('account');
         $insert->columns(array('username', 'password'));
         foreach ($account_rows as $account_rows_row) {
             $insert->values($account_rows_row);
             $statement = $sql->prepareStatementForSqlObject($insert);
             $results = $statement->execute();
             if ($results->getAffectedRows() != 1) {
                 throw new \Zend\Db\Exception\ErrorException();
             }
         }
     }
 }