PHP code example of vitexsoftware / ease-fluentpdo

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

    

vitexsoftware / ease-fluentpdo example snippets



onfigure database connection
define('DB_TYPE', 'mysql');
define('DB_HOST', 'localhost');
define('DB_DATABASE', 'myapp');
define('DB_USERNAME', 'user');
define('DB_PASSWORD', 'password');

// Create a database-backed object
class User extends \Ease\SQL\Engine {
    public function __construct($identifier = null) {
        $this->myTable = 'users';
        $this->keyColumn = 'id';
        parent::__construct($identifier);
    }
}

// Usage example
$user = new User();
$user->setDataValue('name', 'John Doe');
$user->setDataValue('email', '[email protected]');
$user->save(); // Inserts or updates the record

define('DB_TYPE', 'mysql');
define('DB_HOST', 'localhost');
define('DB_PORT', '3306');
define('DB_DATABASE', 'myapp');
define('DB_USERNAME', 'dbuser');
define('DB_PASSWORD', 'password');
define('DB_SETUP', 'SET NAMES utf8mb4');

define('DB_TYPE', 'pgsql');
define('DB_HOST', 'localhost');
define('DB_PORT', '5432');
define('DB_DATABASE', 'myapp');
define('DB_USERNAME', 'postgres');
define('DB_PASSWORD', 'password');

define('DB_TYPE', 'sqlite');
define('DB_DATABASE', '/path/to/database.sqlite');

// Create a model class
class Article extends \Ease\SQL\Engine {
    public function __construct($identifier = null) {
        $this->myTable = 'articles';
        $this->keyColumn = 'id';
        parent::__construct($identifier);
    }
}

// Create new record
$article = new Article();
$article->setDataValue('title', 'My First Article');
$article->setDataValue('content', 'This is the content...');
$article->setDataValue('author_id', 1);
$savedId = $article->save();

// Load existing record
$article = new Article(1);
echo $article->getDataValue('title');

// Update record
$article->setDataValue('title', 'Updated Title');
$article->save();

// Delete record
$article->delete();

$engine = new \Ease\SQL\Engine();

// Select with conditions
$users = $engine->listingQuery()
    ->from('users')
    ->where('active = ?', 1)
    ->where('created_at > ?', '2023-01-01')
    ->orderBy('name ASC')
    ->fetchAll();

// Complex joins
$articles = $engine->listingQuery()
    ->from('articles a')
    ->leftJoin('users u ON a.author_id = u.id')
    ->select('a.*, u.name as author_name')
    ->where('a.published = ?', 1)
    ->fetchAll();

// Configure SQL logging
define('DB_DEBUG', true);

// Log messages to database
$logger = new \Ease\Logger\LogToSQL();
$logger->addToLog('Application started', 'info');
$logger->addToLog('User login failed', 'warning', ['user_id' => 123]);
json
    ""deb/ease-fluentpdo": "*"
    },
    "repositories": [
        {
            "type": "path",
            "url": "/usr/share/php/EaseSQL",
            "options": {
                "symlink": true
            }
        }
    ]