There is a code:

$query = "SELECT * FROM articlePrev WHERE articletype = ? ORDER BY date DESC LIMIT ?,?"; $stmt = $this->pdo->prepare($query); $stmt->execute(array(1,1,5)); return $stmt->fetchAll(PDO::FETCH_ASSOC); 

Which should return the first five rows from the database, but in the end it returns an empty array. If you substitute the parameters directly, like this:

  $query = "SELECT * FROM articlePrev WHERE articletype = 1 ORDER BY date DESC LIMIT 1,5"; 

That records are displayed. What am I doing wrong?

1 answer 1

Well, array is mainly used with INSERT .
For example:

  $len = count($manga_paragraf_name_a); $dbSet = $db->prepare('INSERT INTO m_paragraf (id_main, name, src_original) VALUES (:id_main, :name, :src_original);'); for($i = 0; $i < $len; $i++){ $dbSet->execute(array( ':name' => $manga_paragraf_name_a[$i], ':id_main' => $id, ':src_original' => $manga_paragraf_href_a[$i] )); } $dbSet->fetchAll(); 

In your case, you can:

  $query = "SELECT * FROM articlePrev WHERE articletype = ? ORDER BY date DESC LIMIT :start,:count"; $stmt = $this->pdo->prepare($query); $stmt->bindValue(':start', 1); $stmt->bindValue(':count', 5); $dbSet->execute(); $result = $stmt->fetchAll(); return $result; // можешь глянуть что пришло print_r($result); 
  • Earned, thanks. - Alexey Vladimirovich
  • Mostly, it does not mean that it will not work, somewhere it has a cant. - Jean-Claude
  • Strange that earned, nobody installs the articletype. Maybe he just performs another request? :) - splash58