File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <documentation xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3+ xsi : noNamespaceSchemaLocation =" https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
4+ title =" Prepared SQL"
5+ >
6+ <standard >
7+ <![CDATA[
8+ When querying the database, you should use $wpdb->prepare() to escape and quote the contents of variables. This prevents SQL injection.
9+ Use placeholders for all variables used in the query. You should not use variable interpolation or concatenation.
10+ ]]>
11+ </standard >
12+ <code_comparison >
13+ <code title =" Valid: Placeholders with $wpdb->prepare() used for all variables in query." >
14+ <![CDATA[
15+ $wpdb->prepare(
16+ 'SELECT * from table
17+ WHERE field = <em>%s</em>',
18+ <em>$_GET['foo']</em>
19+ );
20+ ]]>
21+ </code >
22+ <code title =" Invalid: Interpolated variables used in $wpdb->query()." >
23+ <![CDATA[
24+ $wpdb->query(
25+ "SELECT * from table
26+ WHERE field = <em>{$_GET['foo']}</em>"
27+ );
28+ ]]>
29+ </code >
30+ </code_comparison >
31+
32+ <code_comparison >
33+ <code title =" Valid: Placeholders with $wpdb->prepare() used for all variables in query." >
34+ <![CDATA[
35+ $wpdb->prepare(
36+ 'SELECT * from table
37+ WHERE field = <em>%s</em>',
38+ <em>$value</em>
39+ );
40+ ]]>
41+ </code >
42+ <code title =" Invalid: Concatenation of variables used in $wpdb->*()." >
43+ <![CDATA[
44+ $wpdb->get_results(
45+ "SELECT * from table
46+ WHERE field = <em>" . $value</em>
47+ );
48+ ]]>
49+ </code >
50+ </code_comparison >
51+ </documentation >
You can’t perform that action at this time.
0 commit comments