From 226e81f7ab9dfd71035fce2defd61f3111e9babc Mon Sep 17 00:00:00 2001 From: Tuan Pham Ngoc Date: Sat, 17 Jul 2021 17:40:29 +0700 Subject: [PATCH] Fix prepared statement, we need different parameters to bind same value :( --- .../com_weblinks/src/Model/WeblinksModel.php | 5 +++-- .../com_weblinks/src/Model/CategoryModel.php | 10 ++++++---- .../com_weblinks/src/Model/WeblinkModel.php | 12 +++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/administrator/components/com_weblinks/src/Model/WeblinksModel.php b/src/administrator/components/com_weblinks/src/Model/WeblinksModel.php index 5fb0f64..eeee9a4 100644 --- a/src/administrator/components/com_weblinks/src/Model/WeblinksModel.php +++ b/src/administrator/components/com_weblinks/src/Model/WeblinksModel.php @@ -251,8 +251,9 @@ class WeblinksModel extends ListModel else { $search = '%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'); - $query->where('(' . $db->quoteName('a.title') . ' LIKE :search OR ' . $db->quoteName('a.alias') . ' LIKE :search)') - ->bind(':search', $search); + $query->where('(' . $db->quoteName('a.title') . ' LIKE :title OR ' . $db->quoteName('a.alias') . ' LIKE :alias)') + ->bind(':title', $search) + ->bind(':alias', $search); } } diff --git a/src/components/com_weblinks/src/Model/CategoryModel.php b/src/components/com_weblinks/src/Model/CategoryModel.php index 13026ed..b6140a2 100644 --- a/src/components/com_weblinks/src/Model/CategoryModel.php +++ b/src/components/com_weblinks/src/Model/CategoryModel.php @@ -175,10 +175,12 @@ class CategoryModel extends ListModel { $nullDate = $db->getNullDate(); $nowDate = Factory::getDate()->toSql(); - $query->where('(a.publish_up = :nullDate OR a.publish_up <= :nowDate)') - ->where('(a.publish_down = :nullDate OR a.publish_down >= :nowDate)') - ->bind(':nullDate', $nullDate) - ->bind(':nowDate', $nowDate); + $query->where('(a.publish_up = :publishUpNullDate OR a.publish_up <= :publishUpNowDate)') + ->where('(a.publish_down = :publishDownNullDate OR a.publish_down >= :publishDownNowDate)') + ->bind(':publishUpNullDate', $nullDate) + ->bind(':publishDownNullDate', $nullDate) + ->bind(':publishUpNowDate', $nowDate) + ->bind(':publishDownNowDate', $nowDate); } // Filter by language diff --git a/src/components/com_weblinks/src/Model/WeblinkModel.php b/src/components/com_weblinks/src/Model/WeblinkModel.php index 7ddf6d9..30dca7a 100644 --- a/src/components/com_weblinks/src/Model/WeblinkModel.php +++ b/src/components/com_weblinks/src/Model/WeblinkModel.php @@ -91,7 +91,7 @@ class WeblinkModel extends ItemModel $query = $db->getQuery(true) ->select($this->getState('item.select', 'a.*')) ->from('#__weblinks AS a') - ->where($db->quoteName('id') . ' = :id') + ->where($db->quoteName('a.id') . ' = :id') ->bind(':id', $pk, ParameterType::INTEGER); // Join on category table. @@ -119,10 +119,12 @@ class WeblinkModel extends ItemModel $nullDate = $db->getNullDate(); $nowDate = Factory::getDate()->toSql(); - $query->where('(a.publish_up = :nullDate OR a.publish_up <= :nowDate)') - ->where('(a.publish_down = :nullDate OR a.publish_down >= :nowDate)') - ->bind(':nullDate', $nullDate) - ->bind(':nowDate', $nowDate); + $query->where('(a.publish_up = :publishUpNullDate OR a.publish_up <= :publishUpNowDate)') + ->where('(a.publish_down = :publishDownNullDate OR a.publish_down >= :publishDownNowDate)') + ->bind(':publishUpNullDate', $nullDate) + ->bind(':publishDownNullDate', $nullDate) + ->bind(':publishUpNowDate', $nowDate) + ->bind(':publishDownNowDate', $nowDate); } // Filter by published state.