Add databases to PHP 7 projects

Prerequisite

 

Instalación

$ gorilla plugin add db_php7

To uninstall:

$ gorilla plugin remove db_php7

 

How to use it

To use the DB plugin for PHP7 you have to create a new project, select the PHP7 installer and choose one of the three kind of database which are in the options selector.

If you select no option and you need to select later a database, you’ll have to command again the project passing the parameter -f.

 

When the project is created you can connect to the database and use the local methods of each controller (MySQL, PostgreSQL, MongoDB).

Don’t forget that GorillaJS always uses the port which is in the official documentation of each engine. The hosts name is created with the domain name you had chosen for your project plus the technology name ahead by a “_”

Here you have some php examples of database connections for each engine.

 

MariaDB (MySQL)

$connection = mysqli_connect("yourproject.local_mysql", "yourusername", "yourdatabasepassword", "yourdatabasename");

 

PostgreSQL

$connection = pg_connect("host=yourproject.local_postgresql dbname=yourdatabasename user=yourusername password=yourdatabasename");

 

MongoDB

$manager = new MongoDB\Driver\Manager("mongodb://yourusername:yourpassword@yourproject.local_mongo/yourdatabasename");

The NodeJS installer

The NodeJS template that comes as a default in GorillaJS uses the Express.js framework to start a server and return a response. This is optional, and once the application is running we can eliminate this server and use the application in any other way.

FAQ’s

Why do you need to free the port 80? Can you make your own installers? Can you use GorillaJS in a remote server?