How to add clearfix class according to to the posts number?

Try to update your second code part with

$count = 1;

foreach( $pages as $post ) { 
  setup_postdata($post);

  // show your post here

  if ($count++ % 3 === 0)
    echo '<div class="clearfix"></div>';

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)