Database and Middleware example
Thanks for your framework. I try to use this, but i have a couple of questions.
- Can you add some example for Slim Middleware integration?
- JWT
- Rate Limit
- Explain an example the correct way to mysql connect with illuminate/database
I'll show examples of using Slim middleware and DB connection with Laravel little bit later on docs.
You have to add to your composer.json:
composer require illuminate/database
And use Eloquent somewhere on the app like this:
...
use Illuminate\Database\Capsule\Manager as ORM;
...
$orm = new ORM;
$orm->addConnection([
'driver' => getenv('DB_TYPE'),
'host' => getenv('DB_HOST'),
'port' => getenv('DB_PORT'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASSWORD'),
'options' => [ \PDO::ATTR_TIMEOUT => 5 ],
]);
$orm->setAsGlobal();
...
$rows = ORM::select("SELECT * FROM table");
...
Thank you, i will wait for your examples. I should say that JWT & Rate Limit need to be included in base package, because these are main middleware for REST. You have tested the Comet with Eloquent, how many rps we can expect?
Eloquent performance is only at 50% of the equivalent PDO queries with prepared statements. Not good but no so bad either. I suppose Eloquent with entity models will be even slower. I'm struggling to find performant and popular ORM framework in PHP so stick with Eloquent now.
Hi, I recommend the Idiorm, I have been using it for a few years, very simple and easy to use, but without the extra resources of Eloquent.