PHP code example of erkineren / sql-manipulator
1. Go to this page and download the library: Download erkineren/sql-manipulator 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/ */
erkineren / sql-manipulator example snippets
// SQL before manipulation
$sql = "SELECT sa.id FROM s_articles sa WHERE sa.active = 1";
$manipulator = new SqlManipulator($sql);
try {
$manipulator
->addWhere("AND (sa.id = 5 OR sa.name LIKE '%al-%')")
->addWhere("OR sas.name = 'test'")
->addJoin("JOIN s_articles_details sad ON sad.articleID = sa.id")
->addJoin("JOIN s_articles_supplier sas ON sas.id = sa.supplierID")
->addSelectColumn('sad.ordernumber, COUNT(sad.id) as variant_count, sas.name')
->addSelectColumn("(SELECT id*2 FROM s_articles WHERE id = sa.id) as subq")
->addHaving("variant_count > 1")
->addGroupBy("sa.id");
} catch (SqlManipulatorException $e) {
echo $e->getMessage();
}
// SQL after manipulation
echo $manipulator->getSql();