PHP code example of wriver4 / activerecord

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

    

wriver4 / activerecord example snippets


$loader = addPsr4('Models\\', __dir__.'\Models');
// What? Why? Composers base path is vendor and I don't want to update Composer for every new Model.

//Simple Config
$cfg = Activerecord\Config::instance();
$cfg->setConnections(array(
    'development' =>
    'mysql://root:root@localhost/treebark?charset=utf8'));

namespace Models;

class Bar \\ for table name bars by convention
        extends \Activerecord\Model \\ leading slash 

$bars = Models\Bar::find(1)->to_array();
echo $bars['name'];
echo '<br>';
$bars = Models\Bar::all();
foreach ($bars as $bar)
{
    echo '<br> id:';
    echo $bar->id;
    echo '<br> Name of Bar:';
    echo $bar->name;
    echo '<br> Address:';
    echo $bar->address;
    echo '<br>';
}