Pro Stock Tool uses MySQL (or MariaDB) as its database backend. This guide covers database installation, configuration, table creation, and connection setup.
USE prostocktool;CREATE TABLE usuarios ( id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(100) NOT NULL UNIQUE, nombre VARCHAR(100) NOT NULL, identidad VARCHAR(20) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, creado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP, actualizado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX idx_email (email), INDEX idx_identidad (identidad)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
This table stores user account information with:
id: Unique user identifier
email: User email (unique)
nombre: User full name
identidad: National ID number (6-20 digits)
password: Bcrypt hashed password
creado_en: Account creation timestamp
actualizado_en: Last update timestamp
2
Create Bodegas Table
CREATE TABLE bodegas ( id INT AUTO_INCREMENT PRIMARY KEY, nombre VARCHAR(100) NOT NULL UNIQUE, descripcion VARCHAR(300), fecha_creacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP, fecha_actualizacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX idx_nombre (nombre)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
This table manages warehouse/storage locations with:
id: Unique warehouse identifier
nombre: Warehouse name (unique, max 100 chars)
descripcion: Optional description (max 300 chars)
fecha_creacion: Creation timestamp
fecha_actualizacion: Last update timestamp
3
Create Categorias Table
CREATE TABLE categorias ( id INT AUTO_INCREMENT PRIMARY KEY, nombre VARCHAR(100) NOT NULL UNIQUE, descripcion TEXT, activo BOOLEAN DEFAULT TRUE, fecha_creacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP, fecha_actualizacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX idx_nombre (nombre), INDEX idx_activo (activo)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4
Create Subcategorias Table
CREATE TABLE subcategorias ( id INT AUTO_INCREMENT PRIMARY KEY, categoria_id INT NOT NULL, nombre VARCHAR(100) NOT NULL, descripcion TEXT, activo BOOLEAN DEFAULT TRUE, fecha_creacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP, fecha_actualizacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (categoria_id) REFERENCES categorias(id) ON DELETE CASCADE, INDEX idx_categoria (categoria_id), INDEX idx_nombre (nombre)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5
Create Proveedores Table
CREATE TABLE proveedores ( id INT AUTO_INCREMENT PRIMARY KEY, nombre VARCHAR(100) NOT NULL, contacto VARCHAR(100), telefono VARCHAR(20), email VARCHAR(100), direccion VARCHAR(255), ciudad VARCHAR(100), pais VARCHAR(100), activo BOOLEAN DEFAULT TRUE, fecha_creacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP, fecha_actualizacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX idx_nombre (nombre), INDEX idx_activo (activo)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
6
Create Parametros Table
CREATE TABLE parametros ( id INT AUTO_INCREMENT PRIMARY KEY, tipo VARCHAR(50) NOT NULL, nombre VARCHAR(100) NOT NULL, descripcion TEXT, activo BOOLEAN DEFAULT TRUE, fecha_creacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP, fecha_actualizacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX idx_tipo (tipo), INDEX idx_nombre (nombre)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
This table stores system parameters like movement concepts and inventory types.
7
Create Productos Table (Optional)
CREATE TABLE productos ( id INT AUTO_INCREMENT PRIMARY KEY, codigo VARCHAR(50) NOT NULL UNIQUE, nombre VARCHAR(200) NOT NULL, descripcion TEXT, categoria_id INT, subcategoria_id INT, bodega_id INT, proveedor_id INT, precio_compra DECIMAL(10,2), precio_venta DECIMAL(10,2), stock_actual INT DEFAULT 0, stock_minimo INT DEFAULT 0, stock_maximo INT DEFAULT 0, fecha_vencimiento DATE, activo BOOLEAN DEFAULT TRUE, fecha_creacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP, fecha_actualizacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (categoria_id) REFERENCES categorias(id) ON DELETE SET NULL, FOREIGN KEY (subcategoria_id) REFERENCES subcategorias(id) ON DELETE SET NULL, FOREIGN KEY (bodega_id) REFERENCES bodegas(id) ON DELETE RESTRICT, FOREIGN KEY (proveedor_id) REFERENCES proveedores(id) ON DELETE SET NULL, INDEX idx_codigo (codigo), INDEX idx_nombre (nombre), INDEX idx_categoria (categoria_id), INDEX idx_bodega (bodega_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
The database connection is configured in database/conexion.php:
<?php$host = "localhost";$user = "root";$pass = "";$db = "prostocktool";$conn = new mysqli($host, $user, $pass, $db);if ($conn->connect_errno) { http_response_code(500); echo json_encode(["error" => "Error de conexión a la base de datos"]); exit;}?>
2
Update Credentials
Update the connection parameters with your database credentials:
<?php$host = "localhost"; // Database host$user = "prostockuser"; // Database user$pass = "your_secure_password"; // Database password$db = "prostocktool"; // Database name$conn = new mysqli($host, $user, $pass, $db);$conn->set_charset("utf8mb4"); // Ensure UTF-8 encodingif ($conn->connect_errno) { http_response_code(500); echo json_encode(["error" => "Error de conexión a la base de datos"]); exit;}?>
Never commit database credentials to version control. Use environment variables or a separate config file that is gitignored.