Jump to content
Дизайн и модификация Invision Community IPBSkinsBETA
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Romzes

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

Recommended Posts

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

 

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

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

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

 

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

 

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

Share this post


Link to post

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

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

Share this post


Link to post

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

 

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

 

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

Share this post


Link to post

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

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 ) );
   }
}

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...