| @@ 794-816 (lines=23) @@ | ||
| 791 | * @return array Selected record with table names as keys or NULL if no |
|
| 792 | * data selected. |
|
| 793 | */ |
|
| 794 | public static function selectSingleRecord($query, $types = '', $params = []) |
|
| 795 | { |
|
| 796 | if (!Tools::isInstanceOf($query, new DBPreparedQuery())) { |
|
| 797 | $dbQuery = new DBPreparedQuery($query, $types, $params); |
|
| 798 | } else { |
|
| 799 | $dbQuery = $query; |
|
| 800 | } |
|
| 801 | $stmt = $dbQuery->go(); |
|
| 802 | ||
| 803 | if ($stmt !== false) { |
|
| 804 | $record = null; |
|
| 805 | if ($stmt->num_rows === 1) { |
|
| 806 | $record = self::bindResults($stmt); |
|
| 807 | } |
|
| 808 | $stmt->close(); |
|
| 809 | ||
| 810 | if (is_null($record)) { |
|
| 811 | throw new DBCoreException('No one or more than one records selected.'); |
|
| 812 | } |
|
| 813 | ||
| 814 | return $record; |
|
| 815 | } |
|
| 816 | } |
|
| 817 | ||
| 818 | /** |
|
| 819 | * Executes SQL query with single record and value result and return this value. |
|
| @@ 830-853 (lines=24) @@ | ||
| 827 | * |
|
| 828 | * @return mixed |
|
| 829 | */ |
|
| 830 | public static function selectSingleValue($query, $types = '', $params = []) |
|
| 831 | { |
|
| 832 | if (!Tools::isInstanceOf($query, new DBPreparedQuery())) { |
|
| 833 | $dbQuery = new DBPreparedQuery($query, $types, $params); |
|
| 834 | } else { |
|
| 835 | $dbQuery = $query; |
|
| 836 | } |
|
| 837 | $stmt = $dbQuery->go(); |
|
| 838 | ||
| 839 | if ($stmt !== false) { |
|
| 840 | $value = null; |
|
| 841 | if ($stmt->num_rows === 1) { |
|
| 842 | $stmt->bind_result($value); |
|
| 843 | $stmt->fetch(); |
|
| 844 | } |
|
| 845 | $stmt->close(); |
|
| 846 | ||
| 847 | if (is_null($value)) { |
|
| 848 | throw new DBCoreException('No one or more than one records selected.'); |
|
| 849 | } |
|
| 850 | ||
| 851 | return $value; |
|
| 852 | } |
|
| 853 | } |
|
| 854 | ||
| 855 | /** |
|
| 856 | * Calls DBCore magic methods like: |
|