DEV Community

Kofi Owusu-Afriyie
Kofi Owusu-Afriyie

Posted on

4 2

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs