Menu

Database Config
Working with databases in Leaf

Overview

Databse Overview

Leaf doesn't come with a full featured database layer, however, we have miniature database manipulation methods.
To use these methods,

$database = new Leaf\Config\Database();
Now these methods are available in our code...let's take a look

Database Connection

Mysqli connection

We have prepared a simple mysqli connection object for you

use Leaf\Config\Database; $database = new Database(); $connection = $database->connectMysqli($host, $user, $password, $dbname);

PDO connection

We have prepared a simple PDO connection object for you

use Leaf\Config\Database; $database = new Database(); $connection = $database->connectPDO($host, $dbname, $user, $password);

Using connection in a route

To use the connection object inside a route($leaf) use:

use Leaf\Config\Database; $database = new Database(); $connection = $database->connectPDO($host, $dbname, $user, $password); $leaf->post('/users/add', function() use($connection) { // your code });

Next Steps

Re-routing to index.php
Simple Routing
Request
Response