11# php-database
2- A PHP library for accessing databases easily. The library provide a MySQL/MariaDB flavoured database object
2+ A PHP library for accessing databases easily. This library provides a MySQL/MariaDB flavoured database object
33that abstracts many daily task in SQL writing, such as quoting, escaping, building SQL statements, WHERE
44clauses, error handling and so on.
55
@@ -67,7 +67,7 @@ $arr = $db->queryList('SELECT * FROM #__devtest');
6767$obj = $db->querySingle('SELECT * FROM #__devtest WHERE uid='.$uid);
6868```
6969
70- The interface usually delivers ` stdClass ` objects by default. However, you can name
70+ The interface delivers ` stdClass ` objects by default. However, you can name
7171your own data class so the data will be populated in such a class:
7272
7373```
@@ -147,7 +147,7 @@ $dao = \TgDatabase\DAO($db, '#__users');
147147The default constructor as above makes assumptions about your table:
148148
1491491 . It always returns ` stdClass ` objects.
150- 1 . It assumes that your table has an ` int auto-increment ` primary key that is names ` uid ` .
150+ 1 . It assumes that your table has an ` int auto-increment ` primary key that is named ` uid ` .
151151
152152However, you can tell ` DAO ` your specifics:
153153
@@ -159,7 +159,8 @@ $dao = \TgDatabase\DAO($db, '#__users', 'MyNamespace\\User`);
159159$dao = \TgDatabase\DAO($db, '#__users', 'MyNamespace\\User`, 'id');
160160```
161161
162- ` DAO ` can actually handle non-numeric primary keys. The usage is not recommended though.
162+ ` DAO ` can actually handle non-numeric primary keys. The usage is not recommended though as you need
163+ to create the primary keys yourself.
163164
164165## Finding objects
165166
@@ -191,12 +192,12 @@ $newUser->group = 'webusers';
191192$newUser->active = 1;
192193$newId = $dao->create($newUser);
193194
194- // Updating an existing user
195+ // Update an existing user
195196$user = $dao->get($newId);
196197$user->name = 'Jane Doe';
197198$dao->save($user);
198199
199- // Deleting a user
200+ // Delete a user
200201$dao->delete($user);
201202// or
202203$dao->delete($user->uid);
@@ -276,7 +277,7 @@ class Users extends DAO {
276277 }
277278
278279 public function findByDepartment($department, $order = NULL) {
279- return $this->find(array('department' => $email ), $order);
280+ return $this->find(array('department' => $department ), $order);
280281 }
281282}
282283```
@@ -286,7 +287,7 @@ the new Query API. Please read the [Query API](#query-api) chapter.
286287
287288## Using Data Objects with DAOs
288289
289- As above mentioned, you can use your own data classes. There are actually no
290+ As mentioned above , you can use your own data classes. There are actually no
290291restrictions other than the class needs a no-argument constructor. The main
291292advantage is that this class can have additional methods that have some
292293logic. You can even define additional attributes that will not be saved in
@@ -332,7 +333,7 @@ $products = $model->get('products')->find();
332333Of course, a better idea is to encapsulate this in your own ` DataModel ` subclass:
333334
334335```
335- class MyDataModel extends \TGDatabase \DataModel {
336+ class MyDataModel extends \TgDatabase \DataModel {
336337
337338 public function __construct($database) {
338339 parent::__construct($database);
@@ -630,14 +631,14 @@ $count = $dao->count(Restrictions::eq('name', 'John Doe'));
630631```
631632
632633## Advantages and Limitations
633- The Query API will further ease searching objects in a database and return model classes, using more
634- complex expressions and restrictions. You will be able to dynamically apply restrictions depending on
635- the requirements of your front-end users and your application. And you won 't need the DAO once you
634+ The Query API further eases searching objects in a database and return model classes, using more
635+ complex expressions and restrictions. You are able to dynamically apply restrictions depending on
636+ the requirements of your front-end users and your application. And you don 't need the DAO once you
636637created the ` Query ` object. It is self-contained.
637638
638639However, some limitations exist:
639640
640- * Query API supports basic use cases so far (searching objects with basic restrictions).
641+ * Query API supports basic use cases so far (searching objects with basic restrictions, updates, deleting ).
641642* Only MySQL / MariaDB SQL dialect is produced (but can be extended to other dialects easily when you stick to the API).
642643* A few of the limitations may be ovecome by using the ` SqlExpression ` and ` SqlProjection ` classes:
643644
@@ -646,7 +647,7 @@ However, some limitations exist:
646647$myExpr = Restrictions::sql('my-sql-fragment');
647648
648649// Use a specific projection not supported
649- $myProj = Projections::sql('name, email ');
650+ $myProj = Projections::sql('RANDOM() ');
650651```
651652
652653But feel free to raise an issue (see below) when you need some extension that is not yet supported.
0 commit comments