You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In case you want to update data of a database, you can use the method `DB::update()`.
139
+
140
+
The following steps are required:
141
+
142
+
1. Choose a table with the method `DB::table()`.
143
+
2. Update the data with the method `DB::update()`.
144
+
145
+
Example:
146
+
147
+
```php
148
+
if (
149
+
$db->table('users')->update(
150
+
[
151
+
'username' => 'test123', // new data
152
+
'password' => 'password123',
153
+
],
154
+
[
155
+
'username' => 'test', // where clause
156
+
'password' => 'password',
157
+
]
158
+
)
159
+
) {
160
+
echo 'Data has successfully been updated';
161
+
} else {
162
+
echo 'Updating data failed';
163
+
}
164
+
```
165
+
166
+
This will update the record(s) where the `username` is equal to `test` and the `password` is equal to `password` to `test123` for the `username` and `password123` for the `password`.
167
+
168
+
### Deleting Data from Database
66
169
67
-
There is currently no real documentation. But don't worry, it's coming soon!
170
+
In order to delete data from a database, follow these steps:
68
171
69
-
Until then, you can simply take a look at the code and you will probably understand most things as I commented every property and method of the database class.
172
+
1. Choose a table with the method `DB::table()`.
173
+
2. Delete the data with the method `DB::delete()`.
174
+
175
+
Here's an simple example which deletes the record(s) where the `username` is equal to `test`:
176
+
177
+
```php
178
+
if ($db->table('users')->delete([
179
+
'username' => 'test' // where clause
180
+
])) {
181
+
echo 'Data has successfully been deleted';
182
+
} else {
183
+
echo 'Deleting data failed';
184
+
}
185
+
```
70
186
71
187
### Using PDO's functionality
72
188
@@ -100,9 +216,17 @@ $stmt->execute();
100
216
$results = $stmt->fetchAll();
101
217
```
102
218
219
+
### API
220
+
221
+
Looking for a complete overview of each property and method of this database class?
222
+
223
+
Just head over to the [`API.md`](https://github.com/jr-cologne/db-class/blob/master/src/API.md) file where you can find everything you need.
224
+
225
+
It is located in the source (`src`) folder.
226
+
103
227
## Further Examples / Stuff for Testing
104
228
105
-
You want to see further examples for using the database class or you just want to play around with it a little bit?
229
+
You want to see further examples of using the database class or you just want to play around with it a little bit?
106
230
107
231
- You can find further examples in the file [`example/example.php`](https://github.com/jr-cologne/db-class/blob/master/example/example.php).
108
232
- To play around with the database class, you can use the database provided in the file [`example/db-class-example.sql`](https://github.com/jr-cologne/db-class/blob/master/example/db-class-example.sql). Just import it in your database client and you are ready to start!
0 commit comments