PHP code example of esd / postgresql-plugin

1. Go to this page and download the library: Download esd/postgresql-plugin 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/ */

    

esd / postgresql-plugin example snippets



namespace app;
use ESD\Go\GoApplication;
use ESD\Plugins\Postgresql\PostgresqlPlugin;

class Application
{
    /**
     * @throws \DI\DependencyException
     * @throws \DI\NotFoundException
     * @throws \ESD\Core\Exception
     * @throws \ESD\Core\Plugins\Config\ConfigException
     * @throws \ReflectionException
     */
    public static function main()
    {
        $application = new GoApplication();
        $application->addPlug(new PostgresqlPlugin());

        $application->run();
    }
}


use GetPostgresql;

public function test()
{
    $this->postgresql()->query("select * from pg_stat_activity");
    return $res;
}

public function test()
{
    $this->postgresql('test')->query("select * from pg_stat_activity");
    return $res;
}

use DI\Annotation\Inject;

/**
 * @Inject()
 * @var \ESD\Plugins\Postgresql\PostgresDb
 */
protected $postgresql;

public function test(){
	$res = $this->postgresql->query("select * from pg_stat_activity");
	return $res;
}

$res = $this->postgresql()->insert("p_customer", [
            "user_name" => "奥里",
            "contact" => json_encode([
                "QQ" => "123456",
                "Wechat" => "黑暗森林"
            ], JSON_UNESCAPED_UNICODE)
        ]);

$res = $this->postgresql()
	->where("contact->>'phone'", '15838381234')
	->get("p_customer");

$res = $this->postgresql()
	->where("contact->>'phone'", '15838381234')
	->delete("p_customer");

$res = $this->postgresql()
	->orderByd("contact->>'QQ'", "ASC")
	->get("p_customer");

$res = $this->postgresql()
	->groupBy("contact->>'QQ'")
	->get("p_customer");

$res = $this->postgresql()
	->join("p_customer_qq cq", "c.contact->>'QQ' = cq.qq_number", "LEFT")
	->where("c.contact->>'phone'", '15838381234')
	->get("p_customer c", NULL, "c.*, cq.qq_avator");

$res = $this->postgresql()
	->where("contact->>'phone'", '15838381234')
	->has("p_customer");

$sql = $this->postgresql()->getLastQuery();

$exist = $this->postgresql()->tableExists("p_customer");

$db = $this->postgresql();

$db->startTransaction();
...
if (!$db->insert ('myTable', $insertData)) {
    //Error while saving, cancel new record
    $db->rollback();
} else {
    //OK
    $db->commit();
}

$error = $this->postgresql()->getLastError();

$db = $this->postgresql();
$page = 1;
// set page limit to 2 results per page. 20 by default
$db->pageLimit = 2;
$res = $db->paginate("p_customer", $page);

$res = $this->postgresql()
    ->query('SELECT * from p_customer where contact->>'phone' = ?', Array('15838381234'));