Jump to content

Tunning my script


wolves

Recommended Posts

Hi, in my system, when I have to delete some register I need to verify all other tables that uses references from the register I want to delete.
so I have a array that contains all references like this...

[code]
$ref = Array
(
   [0] => cfo0001=cfo0006.cd_abs
   [1] => cfo0001=cfo0017.cd_pod
   [1] => cfo0004=cfo0011.cd_sor
)
[/code]

   [b]cfo0001[/b]=[b]cfo0006[/b].[b]cd_abs[/b]
   my primary key of the table cfo0001 is used  on the table cfo0006 field [b] cd_abs [/b]

   so I use a function that loops through the array verifing all references by using this function


[code]
#$conn, database connection
#$table, table that I will veirfy
#$pkvalue, value for search
function reflist_have_registers($conn,$table,$pkvalue) {  
 $table = strtolower($table);
 #loads my array
 $list = load_reflist();
 #order the tables by sequence
 sort($list);
 while(list($key,$value) = each($list)) {
   $line = new RefListUtils($value);    
   #I use this to get the table name, table reference, and field name
   # EX cfo0004=cfo0011.cd_sor
   #   line->table1 = cfo0004
   #   line->table2 = cfo0011
   #   line->field    = cd_sor
   
   #ok is the table that I have to verify, lets loop
   if($table == $line->table1) {
     for(($i=key($list)-1);$i<count($list);$i++) {
       //it's not the table, lets get out
       if ($line->table1 != $table)
         break 2;
       $table2 = $line->table2;
       $field = $line->field;
       #this functions runs a query equivalent "select count(field) from table where field = myvalue"
       if(lookFieldSql($conn,$table2,$field,"{$field} = ?",$pkvalue,'COUNT')>0)
         return true;
     }
   }
 }
 return false;
}
[/code]

ok it works, but is too slowly, I need a faster way to do this, something that tunes my functions, I don't know, because it's too slowly,

can someone help me?

tks


Link to comment
https://forums.phpfreaks.com/topic/16315-tunning-my-script/
Share on other sites

My function had an error,

It was looping all the array when It found the table,
I ne

after this point
[code]
if($table == $line->table1) {
      for(($i=key($list)-1);$i<count($list);$i++) {
          ...

[/code]

I need to put

[code]
if($table == $line->table1) {
      for(($i=key($list)-1);$i<count($list);$i++) {
          #to get the new value of table
          $line = new RefListUtils($list[$i]);  ...
[/code]

its running good now, but if someone have some idea, please tell me

tks

Link to comment
https://forums.phpfreaks.com/topic/16315-tunning-my-script/#findComment-67766
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.