Hi, I use this code to generate my next PRIMARY code with PURE PHP , as might write in Phalcon, If possible with model
$prefijo ="CLI, TRA, PRO" ONLY 3 letter or IF you analyze the code can change to more
$table = Table to where it will generate the code
$campoPrimario = Field this table as the primary key or you want to generate you the code
$prefijo="CLI"
select ('$prefijo' || (case when max($campoPrimario) IS NULL THEN '0000000001' ELSE LPAD((SUBSTRING(max($campoPrimario), 4) + 1), 10, '0') END)) AS codigo
from $tabla
RESULT="CLI0000000001"
CONSULTATION IS MADE FOR ORACLE DATABASE COMMAND LPDAD ADVANTAGE TO DIVIDE THE CHAIN AS A LEFT OR RIGHT IN EXCEL