PHP code example of dcmunhoz / data-access

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

    

dcmunhoz / data-access example snippets


define("DATA_ACCESS", [
  "driver"   => "mysql",
  "host"     => "localhost",
  "port"     => "3306",
  "dbname"   => "DATA_ACCESS_EXAMPLE",
  "user"     => "root",
  "password" => "",
  "options"  => [
      PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
      PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
  ]
]);

/**
 * User controller example
 */
class UserController extends DataAccess{
  
    /**
     * User Constructor
     */
    function __construct(){
        /** \DataAccess::_construct(ENTITY_NAME, PRIMARY_KEY) */
        parent::__construct("TB_USERS", "ID_USER");
    }
}

$user = new UserController();

$result = $user->raw("INSERT INTO TB_USERS(USER_NAME, PASSW, ID_PROFILE) VALUES(:uname, :upass, :pid)", [
    ":uname" => "user25",
    ":upass" => "mysupersecretpassword",
    ":pid" => '1'
]);

$user = new UserController();

//$result = $user->...->fetch(false);
$result = $user->...->fetch(true);

print_r($result);

$user = new UserController();

$result = $user->find()->fetch(true);

print_r($result);

$user = new UserController();

$result = $user->find()->filter("USER_NAME = :uname AND ID_USER = :uid", [":uname" => "USER1", ":uid" => 1])->fetch();

print_r($result);