PHP code example of mouf / database.querywriter

1. Go to this page and download the library: Download mouf/database.querywriter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mouf / database.querywriter example snippets


// People usually write queries like this:
$sql = "SELECT * FROM products p JOIN companies c ON p.company_id = c.id WHERE 1=1 ";
// They keep testing for parameters, and concatenating strings....
if (isset($params['name'])) {
	$sql .= "AND p.name LIKE '".addslashes($params['name'])."%'";
}
if (isset($params['company'])) {
	$sql .= "AND c.name LIKE '".addslashes($params['company'])."%'";
}
// And so on... for each parameter, we have a "if" statement

$mySelect = Mouf::getMySelectStatement();
$sql = $mySelect->toSql(array("status"=>1, "search"=>"hello"));