PHP code example of gp / dbms
1. Go to this page and download the library: Download gp/dbms 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/ */
gp / dbms example snippets
namespace App\Events;
use Database\Orm\Events;
use Database\Orm\Model;
class AuditEventHandler extends Events
{
public function handle(Model $_model)
{
if ($_model->hasTriggeredEvent(self::EVENT_BEFORE_DELETE)) {
echo "Audit log: A model is about to be deleted.";
}
if ($_model->hasTriggeredEvent(self::EVENT_AFTER_DELETE)) {
echo "Audit log: A model has been deleted.";
}
}
}
class User extends Model
{
public function __construct() {
$this->setTriggerEvent(true);
$this->setEvents([
Events::BEFORE_SAVE => BeforeSave::class // and Events
]);
}
public static function getTableName()
{
return 'users';
}
public function posts()
{
return $this->hasMany(Post::class);
}
}
class Post extends Model
{
public static function getTableName()
{
return 'posts';
}
}
// Fetch a user and their posts
$user = User::find(1); $posts = $user->posts;