|
2 | 2 | [](https://travis-ci.org/webdevlabs/phreak) |
3 | 3 | [](https://www.codacy.com/app/webdevlabs/phreak?utm_source=github.com&utm_medium=referral&utm_content=webdevlabs/phreak&utm_campaign=Badge_Grade) |
4 | 4 | [](https://insight.sensiolabs.com/projects/bd0c18b6-3e25-4c13-8969-7d28bc41eaf3) |
5 | | -[](https://www.versioneye.com/user/projects/58f730d9710da2004fad45d7) |
6 | 5 | [](https://styleci.io/repos/86944823) |
7 | 6 |
|
8 | 7 | ### ultra-light fast php framework powered by: |
@@ -126,3 +125,54 @@ class ... { |
126 | 125 | } |
127 | 126 | } |
128 | 127 | ``` |
| 128 | + |
| 129 | +### Database |
| 130 | +You now have different options for managing your database. There are 2 existing database drivers. |
| 131 | +Sample database wrapper class DB:: and the well known database mapper Eloquent. |
| 132 | + |
| 133 | +**You control what database driver to load directly from config/database.php** |
| 134 | + |
| 135 | +Example PDO driver fetch queries: |
| 136 | +``` |
| 137 | + * Result: single column |
| 138 | + * $count = DB::column('SELECT COUNT(*) FROM `user`); |
| 139 | +
|
| 140 | + * Result: an array(key => value) results (i.e. for making a selectbox) |
| 141 | + * $pairs = DB::pairs('SELECT `id`, `username` FROM `user`); |
| 142 | +
|
| 143 | + * Result: a single row result |
| 144 | + * $user = DB::row('SELECT * FROM `user` WHERE `id` = ?', array($user_id)); |
| 145 | +
|
| 146 | + * Result: a single row result |
| 147 | + * $user = DB::row('SELECT * FROM `user` WHERE `id` = :varname', array(":varname"=>"some variable")); |
| 148 | +
|
| 149 | + * Result: an array of results |
| 150 | + * $banned_users = DB::fetch('SELECT * FROM `user` WHERE `banned` = ?', array(TRUE)); |
| 151 | + |
| 152 | + * Result: any query |
| 153 | + * $dosql = DB::query('UPDATE `settigs` WHERE `setid`=?', ['somesetid']); |
| 154 | + |
| 155 | + * Result: insert user |
| 156 | + * DB::insert('users', ['username'=>'test','password'=>'testpass']); |
| 157 | +
|
| 158 | + * Result: update user password where user_id = 1 |
| 159 | + * DB::update('users', ['password'=>'testpass'], '1', 'user_id'); |
| 160 | + ``` |
| 161 | + |
| 162 | + The new available method for managing your database is Eloquent (from the Laravel framework). |
| 163 | + |
| 164 | + The *Eloquent ORM* provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table. |
| 165 | + |
| 166 | +*Examples of phreak eloquent usage can be found at the '**modules/elog**' made for demonstration.* |
| 167 | + |
| 168 | +Full documentation can be found at [Eloquent's](https://laravel.com/docs/5.7/eloquent) page. |
| 169 | + |
| 170 | + |
| 171 | +### Console Commands |
| 172 | +You can also execute phreak controllers from your console/crontab by calling the console.php file where the parameters are the filename of the controller. |
| 173 | + |
| 174 | +**Calls the App\Commands\SomeController.php with the proper request method.** |
| 175 | +``` |
| 176 | +php console.php SomeController |
| 177 | +``` |
| 178 | +All console controllers are located in the "app/commands" folder. The folder location is defined in the 'app/ConsoleController.php' and can be changed. |
0 commit comments