@@ -8,7 +8,7 @@ The database access is designed around [PreparedStatement](https://github.com/Wo
88
99``` php
1010<?php
11- $statement = \wcf\system\WCF::getDB()->prepareStatement ("SELECT * FROM wcf".WCF_N."_example ");
11+ $statement = \wcf\system\WCF::getDB()->prepare ("SELECT * FROM wcf1_example ");
1212$statement->execute();
1313while ($row = $statement->fetchArray()) {
1414 // handle result
@@ -22,10 +22,10 @@ The example below illustrates the usage of parameters where each value is replac
2222``` php
2323<?php
2424$sql = "SELECT *
25- FROM wcf".WCF_N."_example
25+ FROM wcf1_example
2626 WHERE exampleID = ?
2727 OR bar IN (?, ?, ?, ?, ?)";
28- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql);
28+ $statement = \wcf\system\WCF::getDB()->prepare ($sql);
2929$statement->execute([
3030 $exampleID,
3131 $list, $of, $values, $for, $bar
@@ -44,16 +44,16 @@ You can opt-in to retrieve only a single row from database and make use of short
4444``` php
4545<?php
4646$sql = "SELECT *
47- FROM wcf".WCF_N."_example
47+ FROM wcf1_example
4848 WHERE exampleID = ?";
49- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql, 1);
49+ $statement = \wcf\system\WCF::getDB()->prepare ($sql, 1);
5050$statement->execute([$exampleID]);
5151$row = $statement->fetchSingleRow();
5252```
5353
5454There are two distinct differences when comparing with the example on query parameters above:
5555
56- 1 . The method ` prepareStatement ()` receives a secondary parameter that will be appended to the query as ` LIMIT 1 ` .
56+ 1 . The method ` prepare ()` receives a secondary parameter that will be appended to the query as ` LIMIT 1 ` .
57572 . Data is read using ` fetchSingleRow() ` instead of ` fetchArray() ` or similar methods, that will read one result and close the cursor.
5858
5959### Fetch by Column
@@ -65,8 +65,8 @@ Fetching an array is only useful if there is going to be more than one column pe
6565``` php
6666<?php
6767$sql = "SELECT bar
68- FROM wcf".WCF_N."_example ";
69- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql);
68+ FROM wcf1_example ";
69+ $statement = \wcf\system\WCF::getDB()->prepare ($sql);
7070$statement->execute();
7171while ($bar = $statement->fetchColumn()) {
7272 // handle result
@@ -79,9 +79,9 @@ Similar to fetching a single row, you can also issue a query that will select a
7979``` php
8080<?php
8181$sql = "SELECT bar
82- FROM wcf".WCF_N."_example
82+ FROM wcf1_example
8383 WHERE exampleID = ?";
84- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql, 1);
84+ $statement = \wcf\system\WCF::getDB()->prepare ($sql, 1);
8585$statement->execute([$exampleID]);
8686$bar = $statement->fetchSingleColumn();
8787```
@@ -95,8 +95,8 @@ To fetch all rows of query, you can use `PDOStatement::fetchAll()` with `\PDO::F
9595``` php
9696<?php
9797$sql = "SELECT *
98- FROM wcf".WCF_N."_example ";
99- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql);
98+ FROM wcf1_example ";
99+ $statement = \wcf\system\WCF::getDB()->prepare ($sql);
100100$statement->execute();
101101$rows = $statement->fetchAll(\PDO::FETCH_ASSOC);
102102```
@@ -108,8 +108,8 @@ If you only want to fetch a list of the values of a certain column, you can use
108108``` php
109109<?php
110110$sql = "SELECT exampleID
111- FROM wcf".WCF_N."_example ";
112- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql);
111+ FROM wcf1_example ";
112+ $statement = \wcf\system\WCF::getDB()->prepare ($sql);
113113$statement->execute();
114114$exampleIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
115115```
@@ -123,8 +123,8 @@ This case is covered by `PreparedStatement::fetchMap()`:
123123``` php
124124<?php
125125$sql = "SELECT exampleID, userID
126- FROM wcf".WCF_N."_example_mapping ";
127- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql);
126+ FROM wcf1_example_mapping ";
127+ $statement = \wcf\system\WCF::getDB()->prepare ($sql);
128128$statement->execute();
129129$map = $statement->fetchMap('exampleID', 'userID');
130130```
@@ -138,8 +138,8 @@ If you do not have a combination of columns with unique pairs of values, but you
138138``` php
139139<?php
140140$sql = "SELECT exampleID, userID
141- FROM wcf".WCF_N."_example_mapping ";
142- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql);
141+ FROM wcf1_example_mapping ";
142+ $statement = \wcf\system\WCF::getDB()->prepare ($sql);
143143$statement->execute();
144144$map = $statement->fetchMap('exampleID', 'userID', false);
145145```
@@ -171,10 +171,10 @@ Prepared statements not only protect against SQL injection by separating the log
171171<?php
172172$data = ['abc', 'def', 'ghi'];
173173
174- $sql = "INSERT INTO wcf".WCF_N."_example
174+ $sql = "INSERT INTO wcf1_example
175175 (bar)
176176 VALUES (?)";
177- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql);
177+ $statement = \wcf\system\WCF::getDB()->prepare ($sql);
178178
179179\wcf\system\WCF::getDB()->beginTransaction();
180180foreach ($data as $bar) {
@@ -193,10 +193,10 @@ $data = [
193193 4 => 'ghi'
194194];
195195
196- $sql = "UPDATE wcf".WCF_N."_example
196+ $sql = "UPDATE wcf1_example
197197 SET bar = ?
198198 WHERE exampleID = ?";
199- $statement = \wcf\system\WCF::getDB()->prepareStatement ($sql);
199+ $statement = \wcf\system\WCF::getDB()->prepare ($sql);
200200
201201\wcf\system\WCF::getDB()->beginTransaction();
202202foreach ($data as $exampleID => $bar) {
0 commit comments