PHP code example of wdes / simple-php-model-system

1. Go to this page and download the library: Download wdes/simple-php-model-system 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/ */

    

wdes / simple-php-model-system example snippets



declare(strict_types = 1);

use SimplePhpModelSystem\Database;

rface $em
$db->setConnection($em->getConnection()->getNativeConnection());// Wants a PDO connection object class


declare(strict_types = 1);

use SimplePhpModelSystem\Database;

onfig.dist.php and fill the values
$config     =  



use examples\User;

// Without models

$statement = $db->query(
    'SELECT 1'
);
$this->data = [];
while (($row = $statement->fetch(PDO::FETCH_ASSOC)) !== false) {
    $this->data[] = $row;
}
var_dump($this->data);


// With a model

$user1 = User::create(
    '5c8169b1-d6ef-4415-8c39-e1664df8b954',
    'Raven',
    'Reyes',
    null
);
$user1->save();// If you forget this line, it will only exist in memory
$user1 = User::findByUuid('5c8169b1-d6ef-4415-8c39-e1664df8b954');// Find the user back
$user1->toArray();
//[
//    'user_uuid' => '5c8169b1-d6ef-4415-8c39-e1664df8b954',
//    'first_name' => 'Raven',
//    'last_name' => 'Reyes',
//    'date_of_birth' => null,
//]
$user1->refresh(); // Get it back from the DB
$user1->setLastName('last_name', 'Ali-2');// Change an attribute value (build your own setters using the example)
$user1->update();// Update it
$user1->delete();// Delete it
User::deleteAll();// Delete all
// And more functions, see AbstractModel class