Ok, that's the code:
function SQLCreateTables($company) {
$fp = fopen("cl_onepass.sql", "r"); // cuidadín con la seguridad y pasar rutas por variables
$buffer = "";
while (!feof($fp)) {
$subbuffer = fgets($fp, 1024);
if (!ereg("/\*.*\*/", $subbuffer)) {
$buffer = $buffer.$subbuffer;
}
}
fclose($fp);
$SQLCompID = new tSecureExecutor;
$SQLCompID->OpenQuery("SELECT COM_code FROM COMPANIES WHERE COM_name = '$company'");
$cod_com = $SQLCompID->FieldByName("COM_code");
$SQLCompID->close();
$rplstr = "_" . strval($cod_com);
/* En el script pondremos las tablas en plan parametro_nombretabla */
$buffer = ereg_replace("[\$]{1}", $rplstr , $buffer);
// Supone que empleamos & como separador entra las peticiones del script SQL
$query_array = split("&", $buffer);
reset($query_array);
$SQLExec = new tSecureExecutor;
$SQLExec->AutoCommit = 0;
foreach($query_array as $query){
if (!empty($query)) {
$SQLExec->StartTransaction();
$SQLExec->ExecuteQuery($query);
$SQLExec->commit();
}
}
$SQLExec->close();
$SQLAdminUser = new tSecureExecutor;
$sql_query = "INSERT INTO EMPLOYEE_". strval($cod_com) ." (EMP_login, EMP_password) VALUES ('administrador','administrador')";
echo ($sql_query);
$SQLAdminUser->ExecuteQuery($sql_query);
$SQLAdminUser->close();
}
//********************************************************************************
function SQLDeleteTables($company) {
$fp = fopen("cl_del_onepass.sql", "r"); // cuidadín con la seguridad y pasar rutas por variables
$buffer = "";
while (!feof($fp)) {
$subbuffer = fgets($fp, 1024);
if (!ereg("/\*.*\*/", $subbuffer)) {
$buffer = $buffer.$subbuffer;
}
}
fclose($fp);
$rplstr = "_" . strval($company);
/* En el script pondremos las tablas en plan parametro_nombretabla */
$buffer = ereg_replace("[\$]{1}", $rplstr , $buffer);
$buffer = ereg_replace("¡{1}", "$", $buffer);
// Supone que empleamos & como separador entra las peticiones del script SQL
$query_array = split("&", $buffer);
reset($query_array);
$SQLExec = new tSecureExecutor;
$SQLExec->AutoCommit = 0;
foreach($query_array as $query){
$SQLExec->StartTransaction();
$SQLExec->ExecuteQuery($query);
$SQLExec->commit();
}
$SQLExec->close();
}
Both functions are owned by the same class. The tSecureExecutor class is a simple API to work with Interbase's databases, that not have any complexity. Before this, I've closed all connections to database.
One function is executed after the another one in the test, so I don't use the tables at any moment. Well, I hope to find a solution.
Thank you very much...