Skip to content

Connections

Jason Napolitano edited this page Jan 13, 2023 · 17 revisions

DatabaseFactory uses PHP Data Objects to interact with a variety of databases. When connecting using the PDO Library, we need to pass a connection string into the PDO constructor. To simplify the connection process, DatabaseFactory makes it extremely easy to connect and all we have to do is modify our env file.

By default, DatabaseFactory includes the following connection classes. In this section, we'll see how to configure our env file to work with these different databases and their corresponding connection strings.

MySQL

MySQL is an extremely popular relational database engine that is used by companies and organizations world-wide, and is the default driver that DatabaseFactory ships with. This means that no extra packages require installation. When we want to use the MySQL engine, DatabaseFactory requires that a few values are configured within our env. This includes a username, password, database name and hostname.

DB_DRIVER=mysql
DB_DATABASE=database_name
DB_USERNAME=username
DB_PASSWORD=password
DB_HOSTNAME=127.0.0.1

SQLite3

SQLite is a C-language library that implements a small and blazing fast SQL database engine. The only thing we have to focus on here, is DB_DATABASE and DB_DRIVER, where DB_DATABASE is the relative path of the physical database file, with or without the .db extension.

DB_DRIVER=sqlite
DB_DATABASE=path/to/database.db # with or without the .db extension

MSSQL

Microsoft SQL Server is another relational database engine. By default, DatabaseFactory supports two separate MSSQL drivers: DBLib and SQLSrv. This allows for maximum flexibility when working with a Microsoft SQL Server environemnt.

When connecting to a MSSQL database using the SQLSrv driver, we need to define our ENV configuration as follows:

# coming soon ...

When connecting to a MSSQL database using the DBLib driver, we need to define our ENV configuration as follows:

# coming soon ...

Postgre

When connecting to a Postgre database, we need to define our ENV configuration as follows:

# coming soon ...
Clone this wiki locally