PHP code example of tschueller / phpmysqlgrid

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

    

tschueller / phpmysqlgrid example snippets



PhpMySQLGrid\MySQLGrid;

session_start();

$grid = new MySQLGrid();
$grid->hostname = '127.0.0.1';
$grid->username = 'root';
$grid->password = 'secret-password';
$grid->database = 'test_db';
$grid->table = 'users';
$grid->primary = 'id';
$grid->name = 'users_grid';
$grid->limit = 10;

$grid->columns = array(
    array('field' => 'id', 'caption' => 'ID', 'can_sort' => true, 'can_filter' => false),
    array('field' => 'username', 'caption' => 'Username'),
    array('field' => 'email', 'caption' => 'Email'),
    array('field' => 'active', 'caption' => 'Active', 'type' => PHPMYSQLGRID_BOOLEAN),
);

$grid->execute();

$grid = new PhpMySQLGrid\MySQLGrid();
$grid->hostname = "127.0.0.1";
$grid->username = "root";
$grid->password = "secret-password";
$grid->database = "test_db";
$grid->table = "users";
$grid->primary = "id";
$grid->execute();

$pdo = new PDO("mysql:host=127.0.0.1;dbname=test_db;charset=utf8mb4", "root", "secret-password");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$grid = new PhpMySQLGrid\MySQLGrid();
$grid->setDatabaseConnection($pdo, "pdo_mysql");
$grid->table = "users";
$grid->primary = "id";
$grid->execute();

use PhpMySQLGrid\MySQLGridAssets;

MySQLGridAssets::configure('/assets/phpmysqlgrid');
echo MySQLGridAssets::cssTagsFor();

use PhpMySQLGrid\MySQLGridAssets;

MySQLGridAssets::configure('/assets/phpmysqlgrid');
echo MySQLGridAssets::cssTagsFor('dark');

$grid->cssClass = "theme-default";
// or
$grid->cssClass = "theme-dark";