I'm doing this code:
<?php
$tempSQL = "CREATE TEMPORARY TABLE IF NOT EXISTS tempUsers
SELECT CONCAT(NOMBRE,' 'AP_PATERNO,' ',AP_MATERNO) AS NOMBRE,
EMP_ID, AREA FROM EMPLEADOS WHERE ESTADO = 1";
mysqli_query($conn,$tempSQL);
if(mysqli_affected_rows($conn)<=0)
echo 'No fue posible concretar la información';
else
{
$sql = "SELECT * FROM tempUsers WHERE EMP_ID = $num";
$result = mysqli_query($conn,$sql);
if(!$result)
echo 'Ocurrió un error interno en la base de datos';
else
{
if(mysqli_num_rows($result)<=0)
echo 'No se encontraron coincidencias en la búsqueda';
else
{...}
}
}
mysqli_query($conn,"DROP TEMPORARY TABLE IF EXISTS tempUsers");
?>
My question is, this code is executed with the Jquery event onkeyup
I worry about the performance of the server and the creation and destruction of temporary tables constantly, believe that it would be better to do a stored procedure every hour that makes this operation or creating and destroying tables can not affect the database.
Thank you for your experience.
UPDATE WITH MORE INFORMATION This is the problem, I am doing a search by employee id, name or area, search by the 3 areas, the idea of making a temporary table is because there are employees that have their full name with surnames within the name field or separated by name ap_paternal and ap_maternal. What I have not found a way to find a search by name, Juan + Lopez searches for me because the fields are separated. The only way I came up with is to make a temporary table where to concatenate those names and make the query to that table, that way if it works. I tried to create the temporary table in the database and try to collect the data, but at the time of the connection from PHP it shows me that the table does not exist. And that's why I'm doing this experiment.