PHP code example of fabik / database

1. Go to this page and download the library: Download fabik/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/ */

    

fabik / database example snippets


	use Fabik\Database\DatabaseExtension;

	$configurator->onCompile[] = function($configurator, $compiler) {
		$compiler->addExtension('database', new DatabaseExtension);
	};
	

	

	namespace Blog;

	use Fabik\Database\ActiveRow,
		Fabik\Database\Table;



	class Article extends ActiveRow
	{
	}



	class User extends ActiveRow
	{
		/** @return string */
		public function getRealname()
		{
			return "$this->firstname $this->surname";
		}



		/** @param string */
		public function setRealname($realname)
		{
			list($this->firstname, $this->surname) = explode(' ', $realname);
		}
	}



	class Articles extends Table
	{
		protected $name = 'articles';
	}



	class Users extends Table
	{
		protected $name = 'users';
	}
	

	$articles = $container->articles;

	foreach ($articles->findAll() as $article) {
		echo "$article->title was written by $article->author->realname\n";
	}