Reduce the sql request

This commit is contained in:
Gregory Trolliet 2020-11-23 22:32:31 +01:00
parent 39d4be9eb3
commit dbf62c88bd

13
db.php
View file

@ -95,20 +95,11 @@ class DataBase
while($data = $stmt->fetch()) { while($data = $stmt->fetch()) {
if ($this->areWordsSimilar($data['word'], $word)) { if ($this->areWordsSimilar($data['word'], $word)) {
$word = $data['word']; $word = $data['word'];
$wordId = $data['id_word'];
break; break;
} }
} }
$stmt = $this->db->prepare(" if (isset($wordId)) {
SELECT *
FROM words
WHERE cloud_id = :cid
AND word = :w;
");
$stmt->bindValue(':cid', $cloudId, PDO::PARAM_INT);
$stmt->bindValue(':w', $word, PDO::PARAM_STR);
$stmt->execute();
if ($data = $stmt->fetch()) {
$wordId = $data['id_word'];
$stmt = $this->db->prepare(" $stmt = $this->db->prepare("
UPDATE words UPDATE words
SET count = count + 1 SET count = count + 1