1. Go to this page and download the library: Download carry0987/sanite 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/ */
namespace carry0987\Sanite\Example;
use carry0987\Sanite\Models\DataReadModel;
class UserModel extends DataReadModel
{
// Implement your methods, for example:
public function getUserById(int $userId)
{
$queryArray = [
'query' => 'SELECT * FROM user WHERE uid = ? LIMIT 1',
'bind' => 'i', // This value needs to be relative when using DBUtil::getPDOType
];
$dataArray = [$userId];
return $this->getSingleData($queryArray, $dataArray);
}
public function getAllUsers()
{
$queryArray = [
'query' => 'SELECT * FROM user'
];
return $this->getMultipleData($queryArray);
}
}
use carry0987\Sanite\Example\UserModel;
// Instantiate UserModel
$userModel = new UserModel($sanite);
// Retrieve user information for user with ID 1
$user = $userModel->getUserById(1);
$users = $userModel->getAllUsers();
print_r($user);
print_r($users);