Completed
Push — master ( 5a2551...16ba6c )
by Agel_Nash
03:05
created

example.php (1 issue)

Labels
Severity
1
<?php
2
3
include_once 'vendor/autoload.php';
4
5
$DB = new AgelxNash\Modx\Evo\Database\Database(
6
    'localhost',
7
    'modx',
8
    'homestead',
9
    'secret',
10
    'modx_',
11
    'utf8mb4',
12
    'SET NAMES'
13
);
14
$DB->setDebug(true);
15
16
try {
17
    $DB->connect();
18
    echo ' [ CONNECTION TIME ] ' . $DB->getConnectionTime(true) . ' s. ' . PHP_EOL;
19
    echo ' [ VERSION ] ' . $DB->getVersion() . PHP_EOL;
20
21
    $table = $DB->getFullTableName('site_content');
22
23
    echo ' [ METHOD ] query' . PHP_EOL;
24
    $result = $DB->query('SELECT * FROM ' . $table . ' WHERE parent = 0 ORDER BY pagetitle DESC LIMIT 10');
25
    foreach ($DB->makeArray($result) as $item) {
0 ignored issues
show
It seems like $result can also be of type boolean; however, parameter $result of AgelxNash\Modx\Evo\Database\Database::makeArray() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
    foreach ($DB->makeArray(/** @scrutinizer ignore-type */ $result) as $item) {
Loading history...
26
        echo "\t [ DOCUMENT #ID " . $item['id'] . ' ] ' . $item['pagetitle'] . PHP_EOL;
27
    }
28
29
    echo ' [ METHOD ] select with string' . PHP_EOL;
30
    $result = $DB->select('*', $table, 'parent = 0', 'pagetitle DESC', '10');
31
    foreach ($DB->makeArray($result) as $item) {
32
        echo "\t [ DOCUMENT #ID " . $item['id'] . ' ] ' . $item['pagetitle'] . PHP_EOL;
33
    }
34
35
    echo ' [ METHOD ] select with array' . PHP_EOL;
36
    $result = $DB->select(
37
        ['id', 'pagetitle', 'title' => 'longtitle'],
38
        ['c' => $table],
39
        ['parent = 0'],
40
        'ORDER BY pagetitle DESC',
41
        'LIMIT 10'
42
    );
43
    foreach ($DB->makeArray($result) as $item) {
44
        echo "\t [ DOCUMENT #ID " . $item['id'] . ' ] ' . $item['pagetitle'] . PHP_EOL;
45
    }
46
47
    foreach ($DB->getAllExecutedQuery() as $id => $query) {
48
        echo ' [ QUERY #' . $id . ' ] ' . PHP_EOL;
49
        foreach ($query as $key => $data) {
50
            echo "\t [" . $key . '] ' . $data . PHP_EOL;
51
        }
52
    }
53
    echo ' [ DONE ] ' . PHP_EOL;
54
} catch (Exception $exception) {
55
    echo get_class($exception) . PHP_EOL;
56
    echo "\t" . $exception->getMessage() . PHP_EOL;
57
    echo $exception->getTraceAsString() . PHP_EOL;
58
    exit(1);
59
}
60