1. Go to this page and download the library: Download maplephp/query 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/ */
maplephp / query example snippets
use MaplePHP\Query\Connect;
$handler = new MySQLHandler(
$server,
$user,
$password,
$databaseName,
$port = 3306
);
// Recommend: Set TABLE prefix. This will make your life easier
// MaplePHP will automatically prepend the prefix to the table names.
$handler->setPrefix("maple_");
$handler->setCharset("utf8mb4");
$connect = Connect::setHandler($handler);
$connect->execute();
use MaplePHP\Query\Connect;
$SQLiteHandler = new SQLiteHandler(__DIR__ . "/database.SQLite");
$SQLiteHandler->setPrefix("mp_");
$connect = Connect::setHandler($SQLiteHandler);
$connect->execute();
use MaplePHP\Query\Connect;
$postgreSQLHandler = new PostgreSQLHandler($server, $user, $password, $databaseName, $port = 5432);
$postgreSQLHandler->setPrefix("mp_");
$connect = Connect::setHandler($postgreSQLHandler);
$connect->execute();
use MaplePHP\Query\DB;
$select = DB::select("id,firstname,lastname", ["users", "aliasA"])->whereId(1)->where("status", 0, ">")->limit(1);
$select->join(["login", "aliasB"], "aliasB.user_id = aliasA.id");
$obj = $select->get(); // Get one row result as object
$select = DB::select("id,name,content", "pages")->whereStatusParent(1, 0);
$array = $select->fetch(); // Get all rows as an array
$select->whereRoleStatusParent(1, 1, 0);
// role = '1' AND status = '1' AND Parent = 0
$select->compare(">")->whereStatus(0)->or()->whereRole(1);
// status > '0' OR role = '1'
$select->not()->whereId(1)->whereEmail("[email protected]");
// NOT id = '1' AND email = '[email protected]'
$select->order("id");
// ORDER BY price ASC
$select->order("price", "DESC");
// ORDER BY price DESC
$select->order("id", "ASC")->order("parent", "DESC");
// ORDER BY id ASC, parent DESC
$select->orderRaw("id ASC, parent DESC");
// ORDER BY id ASC, parent DESC
$select->set("firstname", "John")->set("lastname", "Doe");
// Update/insert first- and last name
$select->set(["firstname" => "John", "lastname" => "Doe"])->set("lastname", "Doe");
// Same as above: Update/insert first- and last name
$select->setRaw("msg_id", "UUID()");
// UNPORTECTED and and will not be ENCLOSED!