Skip to content

Commit d73bbb7

Browse files
authored
support mysqli_execute_query (php 8.2+ only) (#425)
1 parent ee522d4 commit d73bbb7

File tree

8 files changed

+48
-24
lines changed

8 files changed

+48
-24
lines changed

config/dba.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ services:
4646
- 'PDO::query#0'
4747
- 'PDO::prepare#0'
4848
- 'mysqli::query#0'
49+
- 'mysqli::execute_query#0'
4950
- 'Doctrine\DBAL\Connection::query#0' # deprecated in doctrine
5051
- 'Doctrine\DBAL\Connection::exec#0' # deprecated in doctrine
5152

@@ -56,6 +57,7 @@ services:
5657
functionNames:
5758
- 'Deployer\runMysqlQuery#0'
5859
- 'mysqli_query#1'
60+
- 'mysqli_execute_query#1'
5961

6062
-
6163
class: staabm\PHPStanDba\Rules\QueryPlanAnalyzerRule
@@ -84,5 +86,6 @@ services:
8486
- 'PDO::query#0'
8587
- 'PDO::prepare#0'
8688
- 'mysqli::query#0'
89+
- 'mysqli::execute_query#0'
8790
- 'Doctrine\DBAL\Connection::query#0' # deprecated in doctrine
8891
- 'Doctrine\DBAL\Connection::exec#0' # deprecated in doctrine

tests/default/config/phpstan.neon.dist

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ parameters:
1212
- bootstrap.php
1313

1414
ignoreErrors:
15-
- '#Function Deployer\\runMysqlQuery\(\) should return array<int, array<int, string>>\|null but return statement is missing.#'
1615
- '#.*has no return type specified.#'
1716
- '#.*return type has no value type specified in iterable type iterable.#'
18-
- '#.*with no value type specified in iterable type array.#'
1917

2018
excludePaths:
21-
analyseAndScan:
22-
- *Fixture/**
23-
- */tests/default/data/pdo-pgsql.php
24-
# XXX cases which are not yet supported by the PdoQueryReflector
25-
- */tests/default/data/query-alias.php
19+
- *Fixture/**
20+
- *tests/*/data/**

tests/defaultFetchAssoc/config/phpstan.neon.dist

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ parameters:
1111
bootstrapFiles:
1212
- bootstrap.php
1313

14+
excludePaths:
15+
- *Fixture/**
16+
- *tests/*/data/**
17+
1418
ignoreErrors:
15-
- '#.*has no return type specified.#'
1619
- '#.*return type has no value type specified in iterable type iterable.#'
17-
18-
excludePaths:
19-
analyseAndScan:
20-
- *Fixture/**

tests/defaultFetchNumeric/config/phpstan.neon.dist

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ parameters:
88
paths:
99
- ../
1010

11+
excludePaths:
12+
- *Fixture/**
13+
- *tests/*/data/**
14+
1115
bootstrapFiles:
1216
- bootstrap.php
1317

1418
ignoreErrors:
15-
- '#.*has no return type specified.#'
1619
- '#.*return type has no value type specified in iterable type iterable.#'
17-
18-
excludePaths:
19-
analyseAndScan:
20-
- *Fixture/**

tests/rules/SyntaxErrorInQueryFunctionRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,18 @@ public function getExpectedErrors(): array
103103
default: throw new \RuntimeException(sprintf('Unsupported DBA_REFLECTOR %s', $dbaReflector));
104104
}
105105
}
106+
107+
public function testMysqliExecuteQuery(): void
108+
{
109+
if (\PHP_VERSION_ID < 80200) {
110+
self::markTestSkipped('Test requires PHP 8.2.');
111+
}
112+
113+
$this->analyse([__DIR__.'/data/mysqli_execute_query.php'], [
114+
[
115+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
116+
11,
117+
],
118+
]);
119+
}
106120
}

tests/rules/config/phpstan.neon.dist

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ parameters:
88
paths:
99
- ../
1010

11+
excludePaths:
12+
- *Fixture/**
13+
- *tests/*/data/**
14+
1115
bootstrapFiles:
1216
- bootstrap.php
1317

1418
ignoreErrors:
1519
- '#.*has no return type specified.#'
16-
- '#.*with no type specified.#'
17-
- '#.*with no value type specified in iterable type array.#'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace MysqliExecuteQuery;
4+
5+
class Foo
6+
{
7+
public function syntaxError(\mysqli $mysqli)
8+
{
9+
$mysqli->execute_query('SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada');
10+
11+
mysqli_execute_query($mysqli, 'SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada');
12+
}
13+
}

tests/stringify/config/phpstan.neon.dist

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ parameters:
88
paths:
99
- ../
1010

11+
excludePaths:
12+
- *Fixture/**
13+
- *tests/*/data/**
14+
1115
bootstrapFiles:
1216
- bootstrap.php
1317

1418
ignoreErrors:
15-
- '#.*has no return type specified.#'
1619
- '#.*return type has no value type specified in iterable type iterable.#'
17-
18-
excludePaths:
19-
analyseAndScan:
20-
- *Fixture/**

0 commit comments

Comments
 (0)