PHP code example of arojunior / php-orm-pdo

1. Go to this page and download the library: Download arojunior/php-orm-pdo 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/ */

    

arojunior / php-orm-pdo example snippets


use SimpleORM\core\model\Model;

class AppModel extends Model
{
    public $db_config = [
        'db_host' => '192.168.1.1',
        'db_name' => 'test',
        'db_user' => 'root',
        'db_pass' => ''
    ];
}


use YourNamespace\AppModel;

class Example extends AppModel
{
    public $table = 't_user';
    public $pk    = 'user_id';

    public function getAll()
    {
        return $this->findAll();
    }
}


namespace SimpleORM\app\model;

use SimpleORM\core\model\Model;

class Users extends Model
{
    	/*
        * * Basic configuration
        * These arguments are optionals
        * protected $table = 'users'; //just if the class name a table name are different
        * protected $pk = 'id'; //just if the primary key name is not id
      */	    	    
}


$this->Users->create([
  'name' => 'Junior Oliveira',
  'email' => '[email protected]'
]);

$this->Users->save([
  'id' => 1,
  'name' => 'Junior Oliveira'
]);

$this->Users->lastSavedId();

$this->Users->update([
  'id' => 1,
  'email' => '[email protected]'
]);

$this->Users->delete(['id' => 1]);

$this->Users->findAll(); // fetchAll

$this->Users->findOne(['email' => '[email protected]']);

$this->Users->findById($id);

$this->Users->exists($id);

$this->Users->fetch();
shell
composer