PHP code example of nafisc / simple-eloquent

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

    

nafisc / simple-eloquent example snippets


    use \SimpleEloquent\Connection;
    
    $connection = Connection::set (

        // Connection Name
        'test', 

        // Configuration
        [
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'test',
            'username'  => 'root',
            'password'  => 'password',
        ]

    );

    // Retrieve the Connection
    $connection = Connection::get('test');

    // Execute some Sql
    $result = $connection->select('SELECT * FROM `servers` LIMIT 1');
    $server = $result[0];
    echo $server->ipv4.PHP_EOL;

    . . . 

    // Alternately, you can access the eloquent
    // connection object directly.
    $connection = Connection::get('test')->eloquentConnection();
    $result = $connection->select('SELECT * FROM `servers` LIMIT 1');

    // Retrieve the connection.
    $connection = Connection::get('test');

    // Create a new model for the table 'servers'.
    // See \SimpleEloquent\Connection@model function for more documentation.
    $model = $connection->model('servers');

    // Retrieve a result.
    $result = $model->where('id', 2)->first();
    echo $result->ipv4.PHP_EOL;