This package to create the where part of your MySQL queries from a simple form submission, and everything automatically.
composer require virgiliopontes/autowheremysql
Go to the examples directory in the root of the repository (vendor/virgiliopontes/autowheremysql/examples
).
Open the index.php
with your favorite text editor and take a look at the source code.
Navigate to the directory where the index.php
is allocated.
Exemple
http://127.0.0.1/vendor/virgiliopontes/autowheremysql/
Note: You need to replace 127.0.0.1
with the machine address where the example is
Install Composer if you don't have it.
composer require virgiliopontes/autowheremysql
Or in your composer.json
file add:
{
"require": {
"virgiliopontes/autowheremysql": "~2",
}
}
And the just run:
composer update
and thats it.
Uses in Controller by adding use AutoWhere/AutoWhereMysql
after namespace
<?php
namespace App\Controllers;
use AutoWhere\AutoWhereMysql; //<--- Here
class YourClass
{
//...
public function YourMethod()
{
$autoWhereMysql = new AutoWhere\AutoWhereMysql();
if(isset($_POST['campofiltro'])){
$where = $autoWhereMysql->make_where($_POST['campofiltro'],$_POST['operador'],$_POST['valorfiltro']);
echo $where;
}
}
}
Call me on Twitter @virgiliopontes.
MIT