Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
PdoSqlsrv
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 search
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 * phpMyFAQ SQL Server Driver for PHP (PDO_SQLSRV) based search classes.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2025-2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2025-02-12
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Search\Database;
21
22use Exception;
23use phpMyFAQ\Search\SearchDatabase;
24
25/**
26 * Class PdoSqlsrv
27 *
28 * @package phpMyFAQ\Search\Database
29 */
30class PdoSqlsrv extends SearchDatabase implements DatabaseInterface
31{
32    /**
33     * Prepares the search and executes it.
34     *
35     * @param  string $searchTerm Search term
36     * @throws Exception
37     */
38    #[\Override]
39    public function search(string $searchTerm): mixed
40    {
41        if (is_numeric($searchTerm) && (bool) $this->configuration->get(item: 'search.searchForSolutionId')) {
42            parent::search($searchTerm);
43
44            return $this->resultSet;
45        }
46
47        $query = sprintf(
48            '
49                SELECT
50                    %s
51                FROM 
52                    %s %s %s
53                WHERE
54                    %s
55                    %s',
56            $this->getResultColumns(),
57            $this->getTable(),
58            $this->getJoinedTable(),
59            $this->getJoinedColumns(),
60            $this->getMatchClause($searchTerm),
61            $this->getConditions(),
62        );
63
64        $this->resultSet = $this->configuration->getDb()->query($query);
65
66        return $this->resultSet;
67    }
68}