PHP code example of pollen-solutions / database

1. Go to this page and download the library: Download pollen-solutions/database 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/ */

    

pollen-solutions / database example snippets


use Pollen\Database\DatabaseManager;

$db = new DatabaseManager();

$db->addConnection([
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'pollen-solutions',
    'username'  => 'root',
    'password'  => 'root',
    'charset'   => 'utf8mb4',
    'collation' => 'utf8mb4_general_ci',
    'prefix'    => 'xyz_',
]);

use Illuminate\Database\Schema\Blueprint;
use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$schema = $db->getConnection()->getSchemaBuilder();
$schema->create('posts', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->longText('content')->nullable();
    $table->timestamps();
});


use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$posts = $db->getConnection()->table('posts')->get();

var_dump($posts);
exit;

use Pollen\Database\DatabaseManagerInterface;
use Pollen\Database\DatabaseManager as DB;

/** @var DatabaseManagerInterface $db */
$db->setAsGlobal();

// Now you can call DatabaseManager methods as static.
$posts = DB::table('posts')->get();

var_dump($posts);
exit;

use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$db->bootEloquent();



use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$db->addConnection([
    /**
     * Connection driver (=> '',
    /**
     * SQL hostname.
     * @var string
     */
    'host'           => '127.0.0.1',
    /**
     * SQL socket port.
     * @var int
     */
    'port'           => 3306,
    /**
     * Username credentials.
     * @var string
     */
    'username'       => '',
    /**
     * Password credentials.
     * @var string
     */
    'password'       => '',
    /**
     * Unix socket.
     * @var string
     */
    'unix_socket'    => '',
    /**
     * Charset.
     * @var string
     */
    'charset'        => '',
    /**
     * Collation.
     * @var string
     */
    'collation'      => '',
    /**
     * Table prefix.
     * @var string
     */
    'prefix'         => '',
    /**
     * Enable table prefix indexation.
     * @var bool
     */
    'prefix_indexes' => true,
    /**
     * Enable strict mode.
     * @var bool
     */
    'strict'         => true,
    /**
     * engine.
     * @var string|null
     */
    'engine'         => null,
    /**
     * options.
     * @var array
     */
    'options'        => []
]);



use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$db->addConnection([
    /**
     * Connection driver (e'                => '',
    /**
     * Table prefix.
     * @var string
     */
    'prefix'                  => '',
    /**
     * Enable foreign key constraints.
     * @var bool
     */
    'foreign_key_constraints' => true,
]);



use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$db->addConnection([
    /**
     * Connection driver (=> '',
    /**
     * SQL hostname.
     * @var string
     */
    'host'           => '127.0.0.1',
    /**
     * SQL socket port.
     * @var int
     */
    'port'           => 5432,
    /**
     * Username credentials.
     * @var string
     */
    'username'       => '',
    /**
     * Password credentials.
     * @var string
     */
    'password'       => '',
    /**
     * Charset.
     * @var string
     */
    'charset'        => '',
    /**
     * Table prefix.
     * @var string
     */
    'prefix'         => '',
    /**
     * Enable table prefix indexation.
     * @var bool
     */
    'prefix_indexes' => true,
    /**
     * Schema.
     * @var string
     */
    'schema'         => '',
    /**
     * Table prefix.
     * @var string
     */
    'sslmode'        => '',
]);



use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$db->addConnection([
    /**
     * Connection driver ( => '',
    /**
     * SQL hostname.
     * @var string
     */
    'host'           => 'localhost',
    /**
     * SQL socket port.
     * @var int
     */
    /**
     * Username credentials.
     * @var string
     */
    'username'       => '',
    /**
     * Password credentials.
     * @var string
     */
    'password'       => '',
    /**
     * Charset.
     * @var string
     */
    'charset'        => '',
    /**
     * Table prefix.
     * @var string
     */
    'prefix'         => '',
    /**
     * Enable table prefix indexation.
     * @var bool
     */
    'prefix_indexes' => true,
]);



use Pollen\Database\DatabaseManager;
use Pollen\Support\Env;

Env::load('/var/www/html');

$db = (new DatabaseManager())->withDefaultEnvConnection();

try {
    $db->getConnection();
} catch (InvalidArgumentException $e) {
    trigger_error($e->getMessage());
}
exit;