Skip to content
View in the app

A better way to browse. Learn more.

Дизайн и модификация Invision Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Проверка на ошибку в buildAndFetch

Существует подобный код:

 

$result = $this->DB->buildAndFetch( ... );

// тут должна быть проверка на ошибку...

if ( $this->DB->getTotalRows() > 0 )
{
// update...
}
else
{
// insert...
}

 

Иногда (очень редко) когда происходит атака на форум или что то подобное, в запросе buildAndFetch может возникнуть ошибка, и в следствии чего код ниже выполняется не правильно, то есть вместо обновления записи (update) он добавляет новую (insert).

 

Как мне сделать проверку на ошибку, чтобы в случае её возникновения не выполнять код?

Featured Replies

Что за ошибка?

Если будет sql-ошибка, то код будет остановлен.

  • Author

В самом запросе ошибок нет.

 

Я не понимаю почему getTotalRows возвращает результат 0, и в следствии чего создается дублирующая запись?

 

Полный код: https://pastebin.com/EdrwrWwe

Я бы проверял данные в массиве

if ( !in_array( $this->memberData['member_group_id'], explode( ',', $this->settings['tviewedby_grupos_protegidos'] ) ) )
{
$pesquisa = $this->DB->buildAndFetch( array(
                              'select' => 'id, member_id, tid, vezes',
                              'from'   => 'topic_viewedby',
                              'where'  => "member_id=".$this->memberData['member_id']." and tid=". (int) $this->request['t'] ) );

   if ( $pesquisa['id'] )
   {
       $vezes = $pesquisa['vezes'];
       $this->DB->update( 'topic_viewedby', array( 'dateview' => time(), 'vezes' => $vezes+1), 'id='.$pesquisa['id']  );
   }
   else
   {
       $this->DB->insert( 'topic_viewedby', array( 'tid' => (int) $this->request['t'], 'member_id' => $this->memberData['member_id'], 'dateview' => time(), 'vezes' => 1 ) );
   }
}

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.