Database - Icybrew/Stackoverflow-documentation GitHub Wiki
Database
We can use Database class if we need direct connection to database without going through model.
Example
/* app/controllers/IndexController.php */
<?php
namespace App\Controllers;
use App\Core\DB;
class IndexController extends Controller
{
public function index() {
//$topic = DB::queryObject("SELECT * FROM topics WHERE id = 1");
$topic = DB::table('topics')->select('title')->getAll();
echo $topic->Title;
}
}
Currently supported methods
- DB::queryRaw($query); - Returns PDO Statement
- DB::queryObject($query); - Returns result as object or array of objects
- DB::queryArray($query); - Returns result as an array
QueryBuilder Example
- DB::table('table-name')->select(['id', 'title'])->getAll();