Overview
User management functions handle CRUD operations for users, including listing, creating, updating, deleting, and exporting user data.Core Functions
listar_usuarios
Retrieve all users from the database.Database connection object
Array of user objects, ordered by ID. Returns empty array on error.
SQL Query
obtener_usuario
Get a specific user by their ID.Database connection object
User ID
User data array on success, false on failure
Code Example
crear_usuario
Create a new user account with hashed password.Database connection object
User data array containing:
num_socio- Member numberdni- National IDtelf- Phone numberemail- Email addressnombre- First nameapellido1- First surnameapellido2- Second surnamepassword- Plain text password (will be hashed)rol- User role (admin/socio)
True on success, false on failure
Code Example
Password Hashing
actualizar_usuario
Update an existing user’s information.Database connection object
User ID to update
User data array (same fields as crear_usuario). Password is optional - if empty, it won’t be updated.
True on success, false on failure
Code Example
eliminar_usuario
Delete a user from the system.Database connection object
User ID to delete
True on success, false on failure
Advanced Functions
listar_usuarios_paginado
List users with pagination, search, and sorting capabilities.Database connection object
Filter options:
page(int) - Page number (default: 1)limit(int) - Items per page (default: 10)search(string) - Search termorder_by(string) - Column to sort by (num_socio, nombre, email, dni, rol)order_dir(string) - Sort direction (ASC/DESC)
Array of filtered and paginated users
Code Example
SQL Query Structure
contar_usuarios
Count total users matching the search criteria.Database connection object
Filter options:
search(string) - Search term
Total number of users matching the criteria
export_usuarios_csv
Export users to a CSV file with filtering and sorting.Database connection object
Filter options:
search(string) - Search termorder_by(string) - Column to sort byorder_dir(string) - Sort direction (ASC/DESC)
Outputs CSV file directly to browser and exits. File format includes UTF-8 BOM and semicolon delimiters.
Code Example
CSV Output Headers
Profile Management
obtener_info_usuario
Get complete user information including profile photo.Database connection object
User ID
User info array including foto_perfil field, or false on error
actualizar_perfil_usuario
Update user’s email and phone number.Database connection object
User ID
New email address
New phone number
Result array:
exito(bool) - Success statusmensaje(string) - Result message
Code Example
Profile Photo Functions
subir_foto_perfil
Upload and validate a user profile photo.Database connection object
User ID
$_FILES array from file upload
Result array:
exito(bool) - Success statusmensaje(string) - Result messageruta(string|null) - File path if successful
Validation Rules
- Maximum size: 5MB
- Allowed formats: JPEG, JPG, PNG, GIF
- File must pass
getimagesize()validation
Code Example
obtener_foto_perfil
Get the profile photo path for a user.Database connection object
User ID
Relative path to profile photo, or null if no photo exists
eliminar_foto_perfil
Delete a user’s profile photo.Database connection object
User ID
Result array:
exito(bool) - Success statusmensaje(string) - Result message