To connect the database, use settings :
- indicates whether the database is connected;
if false, the database is not used; by default, false;
core/database/host - address of the database server;
core/database/port - the port number of the database server;
core/database/user - user;
core/database/pass - password;
core/database/base - the name of the database.
The structure of the database tables is arbitrary. In future versions of the framework, it is planned to create a migration mechanism, which will automatically update the database structures up to the project version.
To access the database, use the function db() - a global function that returns an object of the Core\Database class. Available properties and methods:
- reference to the PDO driver database object
db()->query($sql, $param = ) - execution of the query, returns a set of records with field values; the parameters of the request should be set in the array $param, and not in the query $sql this mechanism protects against SQL injection.
db()->execute($sql, $param = ) - query execution, which should not return records, for example, a request to insert data.
db()->first($sql, $param = ) - query execution, returning only the first record; in this case, the result of executing the method is a named array of values.