1. Go to this page and download the library: Download erykai/database 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/ */
erykai / database example snippets
namespace Erykai\Database;
class Users extends Database
{
public function __construct()
{
parent::__construct(
'users',
['name', 'email', 'age'],
'id'
);
}
}
use Erykai\Database\Users;
hp";
$user = new Users();
$user->name = "Alex de Oliveira Vidal";
$user->email = "[email protected]";
$user->password = "102asda030";
$user->age = 10;
$user->save();
var_dump($user->response(), $user->data());
use Erykai\Database\Users;
ETURN ALL
$users = $Users->find()->fetch(true);
foreach ($users as $user) {
echo "O $user->name existe!</br>";
}
//RETURNS THE FIRST RESULT FOUND
$user = $Users->find()->fetch();
echo "O $user->name existe!</br>";
//RETURNS THE FIRST RESULT OF THE QUERY
$user = $Users->find('name, email', 'name=:name', ['name'=>'Leonardo'])->fetch();
echo "O $user->name existe!</br>";
//RETURNS ALL QUERY RESULTS
$users = $Users->find('name, email', 'name=:name', ['name'=>'Leonardo'])->fetch(true);
foreach ($users as $user) {
echo "O $user->name existe!</br>";
}
//RETURNS ALL QUERY RESULTS IN ORDER
$users = $Users
->find('name, email', 'name=:name', ['name'=>'Leonardo'])
->order("email", "DESC")
->fetch(true);
foreach ($users as $user) {
echo "O $user->name existe!</br>";
}
//RETURNS QUERY RESULTS LIMIT
$users = $Users
->find('name, email', 'name=:name', ['name'=>'Leonardo'])
->limit(2)
->fetch(true);
foreach ($users as $user) {
echo "O $user->name existe!</br>";
}
//RETURNS QUERY RESULTS LIMIT USING OFFSET
$users = $Users
->find('name, email', 'name=:name', ['name'=>'Leonardo'])
->limit(2)
->offset(2)
->fetch(true);
foreach ($users as $user) {
echo "O $user->name existe!</br>";
}
//RETURNS GROUPED QUERY RESULTS
$users = $Users
->find('name, email', 'name=:name', ['name'=>'Leonardo'])
->group('name')
->fetch(true);
foreach ($users as $user) {
echo "O $user->name existe!</br>";
}
//RETURNS RESULTS FROM MORE THAN ONE TABLE
$users = $Users
->find('name, email, address', 'name=:name', ['name'=>'Leonardo'])
->inner('INNER JOIN address ON id_user = users.id')
->fetch(true);
foreach ($users as $user) {
echo "O $user->name existe e mora reside no endereço: $user->address!</br>";
}
//response
var_dump($Users->response());