AND, OR and NOT
AND, OR and NOT Operators
With some aditional properties toyour where array ivory can provide you the usage of many operators tht will be covered in this section.
Example And
By default Ivory will add AND at your query like in the example
//import the ivory class
require_once('Operations.php');
//the instance of the ivory
$ivoryOrm = new Operations();
//an array where you add all the field names of the fields you want to select
$arrSelect[] = "name";
$arrSelect[] = "email";
//an array where you add all the table names you want to select
$tables[] = "users";
//an array where you add all the propertie names and the values of your tables
$arrWhere[] = [
"propName" => "id",
"fieldValue" => 3,
];
$arrWhere[] = [
"propName" => "name",
"fieldValue" => "Jon",
];
//the method creates the query : SELECT name,email FROM users WHERE id = 3 AND name = 'Jon';
$select = $ivoryOrm->select($arrSelect, $tables);
$selectWhere = $ivoryOrm->where($select, $arrWhere);
//the method runQuery is responsible to literally run your query into the database;
$result = $ivoryOrm->runQuery($selectWhere);
Example Or
To add a Or condition to your query you have to enable the following property
$arrSelect[] = "name";
$arrSelect[] = "email";
$tables[] = "users";
//an array where you add all the propertie names and the values of your tables
$arrWhere[] = [
"propName" => "id",
"fieldValue" => 3,
"isAnd" => false,
];
$arrWhere[] = [
"propName" => "name",
"fieldValue" => "Jon",
];
//the method creates the query : SELECT name,email FROM users WHERE id = 3 OR name = 'Jon';
$select = $ivoryOrm->select($arrSelect, $tables);
$selectWhere = $ivoryOrm->where($select, $arrWhere);
//the method runQuery is responsible to literally run your query into the database;
$result = $ivoryOrm->runQuery($selectWhere);
Example Not
To a Not condition to your query you have to enable the following property
$arrSelect[] = "name";
$arrSelect[] = "email";
$tables[] = "users";
//an array where you add all the propertie names and the values of your tables
$arrWhere[] = [
"propName" => "id",
"fieldValue" => 3,
"isNot" => true,
];
$arrWhere[] = [
"propName" => "name",
"fieldValue" => "Jon",
];
//the method creates the query : SELECT name,email FROM users WHERE NOT id = 3 AND name = 'Jon';
$select = $ivoryOrm->select($arrSelect, $tables);
$selectWhere = $ivoryOrm->where($select, $arrWhere);
//the method runQuery is responsible to literally run your query into the database;
$result = $ivoryOrm->runQuery($selectWhere);
Example Not Equal
By default Ivory will add = at your query like in the example : WHERE id = 3 AND name = 'Jon' but if you want a not equal field like : WHERE id = 3 AND name != 'Jon' in ivory you should do the following
require_once('Operations.php');
$ivoryOrm = new Operations();
$arrSelect[] = "name";
$arrSelect[] = "email";
$tables[] = "users";
$arrWhere[] = [
"propName" => "id",
"fieldValue" => 3,
];
$arrWhere[] = [
"propName" => "name",
"fieldValue" => "Jon",
"equal" => false,
];
//the method creates the query : SELECT name,email FROM users WHERE id = 3 AND name != 'Jon';
$select = $ivoryOrm->select($arrSelect, $tables);
$selectWhere = $ivoryOrm->where($select, $arrWhere);
//the method runQuery is responsible to literally run your query into the database;
$result = $ivoryOrm->runQuery($selectWhere);