ZF2 - 使用DB \ Adapter连接到Db

I'm really confused!

I'm a beginner with ZF2. Starting to discover it now.

I've followed Starting Skeleton application at Zend manuals. The problem there is that for creating Album module it only uses one table that is impossible in real world. When developing one will have several tables at least.

now I'm reading Web Development with ZF2 by Michael Romer. The thing is that I can't really understand where did he put his code. According to the book - he puts his code inside module.config.php

<?php

$dbParams = array(
    'database'  => 'gott',
    'username'  => 'root',
    'password'  => '',
    'hostname'  => 'localhost',
);

return array(
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) {
                return new Zend\Db\Adapter\Adapter(array(
                    'driver'    => 'pdo',
                    'dsn'       => 'mysql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'],
                    'database'  => $dbParams['database'],
                    'username'  => $dbParams['username'],
                    'password'  => $dbParams['password'],
                    'hostname'  => $dbParams['hostname'],
                ));
            },
        ),
    ),
);

and when I look at the code at GitHub, it says it should be in global.php inside config/autoload.

As I understand, the idea is - we have params and some setup inside global.php, then we detect service started by global.php in module.config.php (with the code below) and assign it to controller:

'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
            'Portfolio\Mapper\Category' => function($sm){
                return new \Portfolio\Mapper\Category($sm->get('Zend\Db\Adapter\Adapter'));
            }
        ),
    ),

So as far as I understand now my controller should be able to detect my DB connection.\

This is my controller code

    public function addCategoryAction(){

        $form = new \Portfolio\Form\CategoryAdd();

        if($this->getRequest()->isPost()){
            $form->setHydrator(new \Zend\Stdlib\Hydrator\Reflection());
            $form->bind(new \Portfolio\Entity\Category());
            $form->setData($this->getRequest()->getPost());

            if($form->isValid()) {
                $newEntity = $form->getData();

                $mapper = $this->getServiceLocator()->get('Portfolio\Mapper\Category');
                $mapper->insert($newEntity);

                $form = new \Portfolio\Form\CategoryAdd();

                return new ViewModel(array(
                    'form' => $form,
                    'success' =>true
                ));
            } else {
                return new ViewModel(array(
                        'form' => $form
                ));
            }
        } else {
            return new ViewModel(array(
                    'form' => $form
            ));
        }

//         $viewObject = new ViewModel(array(
//             'form' => $form
//         ));

//         return $viewObject; 

    }

And here's my Mapper with TableGateway

<?php
namespace Portfolio\Mapper;

use Portfolio\Entity\Category as CategoryEntity;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\TableGateway\Feature\RowGatewayFeature;

class Category extends TableGateway {

    protected $tableName = 'portfolio_categories';
    protected $idCol = 'categoryId';
    protected $entityPrototype = null;
    protected $hydrator = null;

    public function __construct($adapter){

        parent::__construct($this->tableName, $adapter, new RowGatewayFeature($this->idCol));

        $this->entityPrototype = new CategoryEntity();
        $this->hydrator = new \Zend\Stdlib\Hydrator\Reflection;

    }    

    public function insert($entity){
        return parent::insert($this->hydrator->extract($entity));
    }

}

It's not working.

An error occurred
An error occurred during execution; please try again later.
Additional information:
Zend\Db\Adapter\Exception\InvalidQueryException
File:
F:\Server\htdocs\gott\vendor\ZF2\library\Zend\Db\Adapter\Driver\Pdo\Statement.php:245
Message:
Statement could not be executed

Can you tell me the right way to do it and the idea how it should work?

Thank you!