@@ 772-794 (lines=23) @@ | ||
769 | * data selected. |
|
770 | * @throws DBCoreException If no one or more than one records selected. |
|
771 | */ |
|
772 | public static function selectSingleRecord($query, $types = "", $params = []) { |
|
773 | if (!Tools::isInstanceOf($query, new DBPreparedQuery())) { |
|
774 | $dbQuery = new DBPreparedQuery($query, $types, $params); |
|
775 | } else { |
|
776 | $dbQuery = $query; |
|
777 | } |
|
778 | $stmt = $dbQuery->go(); |
|
779 | ||
780 | if ($stmt !== false) { |
|
781 | $record = null; |
|
782 | if ($stmt->num_rows === 1) { |
|
783 | $record = self::bindResults($stmt); |
|
784 | } |
|
785 | $stmt->close(); |
|
786 | ||
787 | if (is_null($record)) { |
|
788 | throw new DBCoreException("No one or more than one records selected."); |
|
789 | } |
|
790 | ||
791 | return $record; |
|
792 | } |
|
793 | ||
794 | return null; |
|
795 | } |
|
796 | ||
797 | /** |
|
@@ 808-831 (lines=24) @@ | ||
805 | * @return mixed |
|
806 | * @throws DBCoreException If no one or more than one records selected. |
|
807 | */ |
|
808 | public static function selectSingleValue($query, $types = "", $params = []) { |
|
809 | if (!Tools::isInstanceOf($query, new DBPreparedQuery())) { |
|
810 | $dbQuery = new DBPreparedQuery($query, $types, $params); |
|
811 | } else { |
|
812 | $dbQuery = $query; |
|
813 | } |
|
814 | $stmt = $dbQuery->go(); |
|
815 | ||
816 | if ($stmt !== false) { |
|
817 | $value = null; |
|
818 | if ($stmt->num_rows === 1) { |
|
819 | $stmt->bind_result($value); |
|
820 | $stmt->fetch(); |
|
821 | } |
|
822 | $stmt->close(); |
|
823 | ||
824 | if (is_null($value)) { |
|
825 | throw new DBCoreException("No one or more than one records selected."); |
|
826 | } |
|
827 | ||
828 | return $value; |
|
829 | } |
|
830 | ||
831 | return null; |
|
832 | } |
|
833 | ||
834 | /** |