@@ 758-780 (lines=23) @@ | ||
755 | * data selected. |
|
756 | * @throws DBCoreException If no one or more than one records selected. |
|
757 | */ |
|
758 | public static function selectSingleRecord($query, $types = "", $params = []) { |
|
759 | if (!Tools::isInstanceOf($query, new DBPreparedQuery())) { |
|
760 | $dbQuery = new DBPreparedQuery($query, $types, $params); |
|
761 | } else { |
|
762 | $dbQuery = $query; |
|
763 | } |
|
764 | $stmt = $dbQuery->go(); |
|
765 | ||
766 | if ($stmt !== false) { |
|
767 | $record = null; |
|
768 | if ($stmt->num_rows === 1) { |
|
769 | $record = self::bindResults($stmt); |
|
770 | } |
|
771 | $stmt->close(); |
|
772 | ||
773 | if (is_null($record)) { |
|
774 | throw new DBCoreException("No one or more than one records selected."); |
|
775 | } |
|
776 | ||
777 | return $record; |
|
778 | } |
|
779 | ||
780 | return null; |
|
781 | } |
|
782 | ||
783 | /** |
|
@@ 794-817 (lines=24) @@ | ||
791 | * @return mixed |
|
792 | * @throws DBCoreException If no one or more than one records selected. |
|
793 | */ |
|
794 | public static function selectSingleValue($query, $types = "", $params = []) { |
|
795 | if (!Tools::isInstanceOf($query, new DBPreparedQuery())) { |
|
796 | $dbQuery = new DBPreparedQuery($query, $types, $params); |
|
797 | } else { |
|
798 | $dbQuery = $query; |
|
799 | } |
|
800 | $stmt = $dbQuery->go(); |
|
801 | ||
802 | if ($stmt !== false) { |
|
803 | $value = null; |
|
804 | if ($stmt->num_rows === 1) { |
|
805 | $stmt->bind_result($value); |
|
806 | $stmt->fetch(); |
|
807 | } |
|
808 | $stmt->close(); |
|
809 | ||
810 | if (is_null($value)) { |
|
811 | throw new DBCoreException("No one or more than one records selected."); |
|
812 | } |
|
813 | ||
814 | return $value; |
|
815 | } |
|
816 | ||
817 | return null; |
|
818 | } |
|
819 | ||
820 | /** |