Skip to content

Commit b40b24b

Browse files
authored
Update README.md
to be continued...
1 parent a6189da commit b40b24b

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

README.md

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# db-class
2-
32
This project is a simple database class with php and pdo.
43

54
## Installation/Setup
6-
75
If you want to use the database class for your own project, you can simply follow these instructions:
86

97
1. Download the ZIP file of this project
108
2. Unzip it and save the file `DB.php` to your own project directory.
119
3. If all requirements, like PHP, PDO and a database that fits to that setup, are fulfilled, you should now be ready to start!
1210

1311
## Basic Usage
14-
1512
If you have successfully "installed" everything, you can use the class like that:
1613

1714
### Require database class
@@ -20,7 +17,6 @@ require_once('your_path/DB.php');
2017
```
2118

2219
### Instantiate Class / Connect to Database
23-
2420
To be able to use the class and connect to the database, you have to instantiate it.
2521

2622
To do that, follow that format:
@@ -60,6 +56,65 @@ Simple example for instantiating the class:
6056
$db = new DB('db-class-example', 'root', '');
6157
```
6258

59+
### Check Connection to Database
60+
The method `connected()` gives you the ability to check if the connection to the database was established successfully.
61+
62+
The method requires no arguments at all, so you can just call it and then it will give you a return value of `true` or `false` based on the fact if the connection was established or not.
63+
64+
Example:
65+
```php
66+
if ($db->connected()) {
67+
echo 'Successfully connected!';
68+
} else {
69+
echo 'Connection failed';
70+
}
71+
```
72+
73+
### Select/Get Data from Database
74+
In order to get data from the database you can use the method `select()` in the following format:
75+
76+
```php
77+
select(string $sql, $where=null, $fetch_mode=PDO::FETCH_ASSOC)
78+
```
79+
80+
The following arguments exist:
81+
82+
#### SQL Query (`$sql`)
83+
The sql to perform the query to the database. (required)
84+
85+
For example:
86+
87+
```sql
88+
SELECT * FROM `users`
89+
```
90+
91+
#### SQL Where Clause (`$where`)
92+
The sql where clause to filter the data from the database and so on. (optional)
93+
94+
Default: `null`
95+
96+
Example:
97+
```sql
98+
WHERE `username` = 'Jack'
99+
```
100+
101+
#### PDO Fetch Mode (`$fetch_mode`)
102+
The [pdo fetch mode](http://php.net/manual/en/pdostatement.fetch.php). Defines in which format the data is returned from the database. (optional)
103+
104+
Default: `PDO::FETCH_ASSOC`
105+
106+
Example:
107+
108+
```php
109+
PDO::FETCH_NUM
110+
```
111+
112+
An simple example for using everything together:
113+
114+
```php
115+
$data = $db->select("SELECT * FROM `users`", "WHERE `username` = 'Jack'", PDO::FETCH_NUM);
116+
```
117+
63118
### Configure Error Handling
64119

65120
If you want to, you can create your own error handling setup before you instantiate the class.

0 commit comments

Comments
 (0)