PHP code example of cisse / as400-bundle
1. Go to this page and download the library: Download cisse/as400-bundle 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/ */
cisse / as400-bundle example snippets
return [
// ...
Cisse\Bundle\As400\As400Bundle::class => ['all' => true],
];
namespace App\Entity;
use Cisse\Bundle\As400\Attribute\Entity;
use Cisse\Bundle\As400\Attribute\Column;
#[Entity(table: 'CUSTOMERS', identifier: 'CUST_ID', database: 'MYLIB')]
class Customer
{
#[Column(name: 'CUST_ID', type: Column::INTEGER_TYPE)]
public ?int $id = null;
#[Column(name: 'CUST_NAME', type: Column::STRING_TYPE)]
public ?string $name = null;
#[Column(name: 'CREATED_DATE', type: Column::DATE_TYPE)]
public ?\DateTime $createdDate = null;
}
namespace App\Repository;
use App\Entity\Customer;
use Cisse\Bundle\As400\Repository\Repository;
class CustomerRepository extends Repository
{
protected const string ENTITY_CLASS = Customer::class;
}
namespace App\Controller;
use App\Repository\CustomerRepository;
class CustomerController
{
public function __construct(
private CustomerRepository $customerRepository
) {}
public function list()
{
// Find all customers
$customers = $this->customerRepository->findAll();
// Find by criteria
$activeCustomers = $this->customerRepository->findBy(['STATUS' => 'ACTIVE']);
// Find one customer
$customer = $this->customerRepository->find(123);
// Count customers
$count = $this->customerRepository->count(['STATUS' => 'ACTIVE']);
}
}
use Cisse\Bundle\As400\Database\Connection\As400Connection;
class MyService
{
public function __construct(
private As400Connection $connection
) {}
public function customQuery()
{
// Raw queries
$results = $this->connection->fetchAll('SELECT * FROM MYLIB.CUSTOMERS WHERE STATUS = ?', ['ACTIVE']);
// CRUD operations
$this->connection->insert('MYLIB.CUSTOMERS', ['NAME' => 'John Doe', 'STATUS' => 'ACTIVE']);
$this->connection->update('MYLIB.CUSTOMERS', ['STATUS' => 'INACTIVE'], ['CUST_ID' => 123]);
$this->connection->delete('MYLIB.CUSTOMERS', ['CUST_ID' => 123]);
}
}