PHP code example of phpaml / data
1. Go to this page and download the library: Download phpaml/data 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/ */
phpaml / data example snippets
use AML\Data\Connection;
use AML\Data\DbContext;
use AML\Data\DbSet;
use AML\Data\Entity;
use AML\Data\Metadata\{Key, Table};
#[Table('users')]
final class User extends Entity
{
#[Key]
public int $id;
public string $name;
public string $email;
}
final class AppDbContext extends DbContext
{
/** @return DbSet<User> */
public function users(): DbSet
{
return $this->set(User::class);
}
}
$db = new AppDbContext(Connection::sqlite(__DIR__ . '/storage/app.sqlite'));
$user = new User();
$user->name = 'Ada';
$user->email = '[email protected]';
$db->users()->add($user);
$page = $db->users()
->where('email', 'LIKE', '%@example.com')
->orderBy('name')
->paginate(page: 1, perPage: 20);