Skip to content

Commit 8a9d046

Browse files
committed
Doc fixes
1 parent f1af21c commit 8a9d046

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

dbObject.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ dbObject - model implementation on top of the MysqliDb
22
Please note, that this library is not pretending to be a full stack ORM but a simple OOP wrapper for mysqlidb
33

44
<hr>
5-
**[Initialization] (#initialization)**
5+
###Initialization
6+
67
1. Include mysqlidb and dbObject classes.
8+
79
2. If you want to use model autoloading instead of manually including them in the scripts use autoload () method.
810

911
```php
@@ -14,9 +16,10 @@ require_once ("libs/dbObject.php");
1416
$db = new Mysqlidb ('localhost', 'user', '', 'testdb');
1517
// enable class autoloading
1618
dbObject::autoload ("models");
17-
1819
```
19-
2. Create simple user class (models/user.php):
20+
21+
3. Create simple user class (models/user.php):
22+
2023
```php
2124
class user extends dbObject {
2225
protected $dbTable = "users";
@@ -29,7 +32,7 @@ class user extends dbObject {
2932
);
3033
}
3134
```
32-
**[Insert Row]**
35+
###Insert Row
3336
1. OOP Way. Just create new object of a needed class, fill it in and call save () method. Save will return
3437
record id in case of success and false in case if insert will fail.
3538
```php
@@ -40,6 +43,7 @@ $id = $user->save ();
4043
if ($id)
4144
echo "user created with id = " . $id;
4245
```
46+
4347
2. Using arrays
4448
```php
4549
$data = Array ('login' => 'demo',
@@ -53,7 +57,8 @@ if ($id == null) {
5357
echo "user created with id = " . $id;
5458
```
5559

56-
2. Multisave
60+
3. Multisave
61+
5762
```php
5863
$user = new user;
5964
$user->login = 'demo';
@@ -68,12 +73,15 @@ $p->save ();
6873

6974
After save() is call both new objects (user and product) will be saved.
7075

71-
**[Selects]**
76+
###Selects
77+
7278
Retrieving objects from the database is pretty much the same process of a get ()/getOne () execution without a need to specify table name.
79+
7380
All mysqlidb functions like where(), orWhere(), orderBy(), join etc are supported.
7481
Please note that objects returned with join() will not save changes to a joined properties. For this you can use relationships.
7582

7683
Select row by primary key
84+
7785
```php
7886
$user = user::byId (1);
7987
echo $user->login;
@@ -93,7 +101,7 @@ $users = user::where ("login", "demo")->get (Array (10, 20));
93101
foreach (users as $u) ...
94102
```
95103

96-
**[Update]**
104+
###Update
97105
To update model properties just set them and call save () method. As well values that needed to by changed could be passed as an array to the save () method.
98106

99107
```php
@@ -107,14 +115,14 @@ $user = user::byId (1);
107115
$user->save ($data);
108116
```
109117

110-
**[Delete]**
118+
###Delete
111119
Use delete() method on any loaded object.
112120
```php
113121
$user = user::byId (1);
114122
$user->delete ();
115123
```
116124

117-
**[Relations]**
125+
###Relations
118126
Currently dbObject supports only hasMany and hasOne relations only. To use them declare $relations array in the model class like:
119127
```php
120128
protected $relations = Array (
@@ -125,20 +133,18 @@ Currently dbObject supports only hasMany and hasOne relations only. To use them
125133
After that you can get related object via variables and do their modification/removal/display:
126134
```php
127135
$user = user::byId (1);
128-
// sql: select * from $persontable where id = $personValue
136+
// sql: select from $persontable where id = $personValue
129137
echo $user->person->firstName . " " . $user->person->lastName . " have the following products:\n";
130-
// sql: select * from $product_table where userid = $userPrimaryKey
138+
// sql: select from $product_table where userid = $userPrimaryKey
131139
foreach ($user->products as $p) {
132140
echo $p->title;
133141
}
134142
```
135-
**[Error checking]**
143+
###Error checking
136144
TBD
137-
**[Validation]**
145+
###Validation
138146
TBD
139-
**[Array as return values]**
147+
###Array as return values
140148
TBD
141-
**[2array and 2json]**
149+
###2array and 2json
142150
TBD
143-
144-

0 commit comments

Comments
 (0)