DEV Community

Kofi Owusu-Afriyie
Kofi Owusu-Afriyie

Posted on

Query your SQL database in the cqured way with ease

Include EntityModel.php to your PHP file and use the namespace Lynq\Entity\EntityModel;

You can also remove the namepsace from the EntityModel.php and you are good to go.
Example

<?php
use Lynq\Entity\EntityModel;

class PracticeModel
{
private $table = 'Media';

/**
* Connect to database in constructor
*/
public function __construct()
{
$dsn = 'mysql:dbname=airMediaDB;host=127.0.0.1';
$user = 'root';
$password = 'glory';
$this->mediaDB = new EntityModel($dsn, $user, $password);
}

/**
* Get ALL items via search $key
*/
public function getItems($key)
{
return $this->mediaDB->table($this->table)
->where('title', 'LIKE', '%'.$key.'%')
->orderBy('id')
->get();
}
Enter fullscreen mode Exit fullscreen mode

https://gitlab.com/snippets/1728351

Top comments (0)