- Added function when entry multiple rows (in this case is when putting categories). - Do test.
58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
class Access extends \Core\Model
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->createTable(
|
|
'user',
|
|
[
|
|
'id int(3) NOT NULL AUTO_INCREMENT',
|
|
'username varchar(25) NOT NULL',
|
|
'password char(13)',
|
|
'registered_at timestamp DEFAULT CURRENT_TIMESTAMP',
|
|
'PRIMARY KEY (id)'
|
|
]
|
|
);
|
|
}
|
|
|
|
public function showAll()
|
|
{
|
|
try {
|
|
$db = static::connectDB();
|
|
|
|
$sql = "SELECT id, username, registered_at FROM user";
|
|
|
|
if ($stmt = $db->query($sql)) {
|
|
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
return true;
|
|
}
|
|
return false;
|
|
} catch (PDOException $e) {
|
|
echo $e->getMessage();
|
|
}
|
|
}
|
|
|
|
public function showSingle($id)
|
|
{
|
|
try {
|
|
$db = static::connectDB();
|
|
|
|
$sql = "SELECT id, username, registered_at FROM user WHERE id = ?";
|
|
|
|
$query = $db->prepare($sql);
|
|
|
|
if ($query->execute([$id])) {
|
|
if ($query->rowCount() === 1) {
|
|
$result = $query->fetchAll(\PDO::FETCH_ASSOC);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
} catch (PDOException $e) {
|
|
echo $e->getMessage();
|
|
}
|
|
}
|
|
}
|