Skip to main content

Database Connection

Simple Invoice uses MySQL/MariaDB as its database system. Database configuration is managed through PHP constants defined in the configuration files.

Configuration Constants

The database connection parameters are defined in config/db.php:
config/db.php
<?php
/*Datos de conexion a la base de datos*/
define('DB_HOST', 'localhost');//DB_HOST:  generalmente suele ser "127.0.0.1"
define('DB_USER', 'root');//Usuario de tu base de datos
define('DB_PASS', '');//Contraseña del usuario de la base de datos
define('DB_NAME', 'simple_invoice');//Nombre de la base de datos
?>
DB_HOST
string
default:"localhost"
Database server host. Typically localhost or 127.0.0.1
DB_USER
string
default:"root"
Database username with access to the Simple Invoice database
DB_PASS
string
default:""
Database user password
DB_NAME
string
default:"simple_invoice"
Name of the database to use

Connection Implementation

The actual database connection is established in config/conexion.php using MySQLi:
config/conexion.php
<?php
# conectare la base de datos
$con=@mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!$con){
    die("imposible conectarse: ".mysqli_error($con));
}
if (@mysqli_connect_errno()) {
    die("Conexión falló: ".mysqli_connect_errno()." : ". mysqli_connect_error());
}
?>
The connection script uses error suppression (@) and dies on failure. Ensure your database credentials are correct before deployment.

Database Schema

Simple Invoice uses a relational database structure with the following core tables:

Core Tables

perfil

Company profile and configuration settings

users

System users and authentication

clientes

Customer information

products

Product catalog

facturas

Invoice headers

detalle_factura

Invoice line items

currencies

Supported currencies (32 currencies)

tmp

Temporary session data

Table Relationships

Key Relationships

  • facturasclientes: Each invoice is linked to a customer via id_cliente
  • facturasusers: Each invoice is created by a user (seller) via id_vendedor
  • facturasdetalle_factura: One-to-many relationship via numero_factura
  • detalle_facturaproducts: Invoice items reference products via id_producto
  • perfilcurrencies: Company profile uses currency symbol from currencies table

Database Setup

1

Create Database

Create a new MySQL database named simple_invoice (or your preferred name)
CREATE DATABASE simple_invoice CHARACTER SET utf8 COLLATE utf8_unicode_ci;
2

Import Schema

Import the database schema from simple_invoice.sql
mysql -u root -p simple_invoice < simple_invoice.sql
3

Configure Connection

Update the constants in config/db.php with your database credentials
4

Verify Connection

Access the application to verify the database connection is working
The default admin user credentials after installation are:
  • Username: admin
  • Password: admin (password hash: $2y$10$MPVHzZ2ZPOWmtUUGCq3RXu31OTB.jo7M9LZ7PmPQYmgETSNn19ejO)

Character Set

The database uses UTF-8 encoding to support international characters:
  • Default charset: utf8
  • Some tables use: utf8_unicode_ci collation
  • Company profile table (perfil): latin1

Storage Engines

  • MyISAM: Used for most tables (clientes, products, facturas, detalle_factura, tmp)
  • InnoDB: Used for users, perfil, and currencies tables
Consider migrating all tables to InnoDB for better transaction support and foreign key constraints.

Build docs developers (and LLMs) love