-
Notifications
You must be signed in to change notification settings - Fork 0
Connections
DatabaseFactory uses PHP Data Objects to interact with a variety of databases. When connecting using the
PDOLibrary, 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 ourenvfile.By default, DatabaseFactory includes the following connection classes. In this section, we'll see how to configure our
envfile to work with these different databases and their corresponding connection strings.
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.1SQLite 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_DATABASEandDB_DRIVER, whereDB_DATABASEis the relative path of the physical database file, with or without the.dbextension.
DB_DRIVER=sqlite
DB_DATABASE=path/to/database.db # with or without the .db extensionMicrosoft SQL Server is another relational database engine. By default, DatabaseFactory supports two separate MSSQL drivers:
DBLibandSQLSrv. This allows for maximum flexibility when working with a Microsoft SQL Server environemnt.When connecting to a MSSQL database using the
SQLSrvdriver, we need to define ourENVconfiguration as follows:
# coming soon ...When connecting to a MSSQL database using the
DBLibdriver, we need to define ourENVconfiguration as follows:
# coming soon ...When connecting to a Postgre database, we need to define our
ENVconfiguration as follows:
# coming soon ...