Ignore:
Timestamp:
Apr 8, 2018, 4:41:57 PM (7 years ago)
Author:
gegorbet
Message:

mods mostly for use of mysqli

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/manage-us3-pipe.php

    r26 r35  
    5555
    5656   // We need the gfacID
    57    $resource = mysql_connect( $dbhost, $user, $passwd );
     57   $resource = mysqli_connect( $dbhost, $user, $passwd, $db );
    5858
    5959   if ( ! $resource )
    6060   {
    61       write_log( "$self process(): Could not connect to MySQL - " . mysql_error() );
     61      write_log( "$self process(): Could not connect to MySQL - " . mysqli_error($resource) );
    6262      write_log( "$self process(): original msg - $msg" );
    6363      return;
    64    }
    65 
    66    if ( ! mysql_select_db( $db, $resource ) )
    67    {
    68      write_log( "$self: Could not select DB $db " . mysql_error( $resource ) );
    69      write_log( "$self process(): original msg - $msg" );
    70      return;
    7164   }
    7265
     
    7669            "LIMIT 1";
    7770
    78    $result = mysql_query( $query, $resource );
     71   $result = mysqli_query( $resource, $query );
    7972   
    8073   if ( ! $result )
     
    8679
    8780   // Set flags for Airavata/Thrift and "Finished..."
    88    list( $gfacID ) = mysql_fetch_row( $result );
    89    mysql_close( $resource );
     81   list( $gfacID ) = mysqli_fetch_row( $result );
     82   mysqli_close( $resource );
    9083
    9184   $is_athrift  = preg_match( "/^US3-A/i", $gfacID );
     
    164157   global $self;
    165158
    166    $resource = mysql_connect( $dbhost, $user, $passwd );
     159   $resource = mysqli_connect( $dbhost, $user, $passwd, $db );
    167160
    168161   if ( ! $resource )
    169162   {
    170       write_log( "$self: Could not connect to DB" );
    171       return;
    172    }
    173 
    174    if ( ! mysql_select_db( $db, $resource ) )
    175    {
    176      write_log( "$self: Could not select DB $db " . mysql_error( $resource ) );
     163     write_log( "$self: Could not connect to DB $db " . mysqli_error( $resource ) );
    177164     return;
    178165   }
     
    183170            "LIMIT 1";
    184171
    185    $result = mysql_query( $query, $resource );
     172   $result = mysqli_query( $resource, $query );
    186173   
    187174   if ( ! $result )
     
    191178   }
    192179
    193    list( $resultID ) = mysql_fetch_row( $result );
     180   list( $resultID ) = mysqli_fetch_row( $result );
    194181
    195182   $query = "UPDATE HPCAnalysisResult SET ";
     
    219206   }
    220207
    221    $query .= "lastMessage='" . mysql_real_escape_string( $message ) . "'" .
     208   $query .= "lastMessage='" . mysqli_real_escape_string( $resource, $message ) . "'" .
    222209             "WHERE HPCAnalysisResultID=$resultID";
    223210
    224    mysql_query( $query, $resource );
    225    mysql_close( $resource );
     211   mysqli_query( $resource, $query );
     212   mysqli_close( $resource );
    226213}
    227214
     
    242229
    243230  // Get data from global GFAC DB
    244   $gLink = mysql_connect( $dbhost, $guser, $gpasswd );
    245   if ( ! mysql_select_db( $gDB, $gLink ) )
    246   {
    247     write_log( "$self: Could not select DB $gDB " . mysql_error( $gLink ) );
     231  $gLink = mysqli_connect( $dbhost, $guser, $gpasswd, $gDB );
     232  if ( ! $gLink )
     233  {
     234    write_log( "$self: Could not select DB $gDB " . mysqli_error( $gLink ) );
    248235    return;
    249236  }
     
    260247  {
    261248     $query = "UPDATE analysis " .
    262               "SET queue_msg='" . mysql_real_escape_string( $message ) . "' " .
     249              "SET queue_msg='" . mysqli_real_escape_string( $gLink, $message ) . "' " .
    263250              "WHERE gfacID='$gfacID'";
    264251
    265252//write_log( "$self process(): updgf-u : status=$status" );
    266      mysql_query( $query, $gLink );
     253     mysqli_query( $gLink, $query );
    267254  }
    268255
     
    270257  {
    271258     $query = "UPDATE analysis SET status='$status', " .
    272               "queue_msg='" . mysql_real_escape_string( $message ) . "' " .
     259              "queue_msg='" . mysqli_real_escape_string( $gLink, $message ) . "' " .
    273260              "WHERE gfacID='$gfacID'";
    274261
    275262//write_log( "$self process(): updgf-s : status=$status" );
    276      mysql_query( $query, $gLink );
     263     mysqli_query( $gLink, $query );
    277264  }
    278265
     
    280267  $query  = "SELECT id FROM analysis " .
    281268            "WHERE gfacID = '$gfacID'";
    282   $result = mysql_query( $query, $gLink );
     269  $result = mysqli_query( $gLink, $query );
    283270  if ( ! $result )
    284271  {
    285     write_log( "$self: bad query: $query " . mysql_error( $gLink ) );
    286     return;
    287   }
    288 
    289   if ( mysql_num_rows( $result ) == 0 )
     272    write_log( "$self: bad query: $query " . mysqli_error( $gLink ) );
     273    return;
     274  }
     275
     276  if ( mysqli_num_rows( $result ) == 0 )
    290277  {
    291278    write_log( "$self: can't find $gfacID in GFAC db" );
     
    293280  }
    294281
    295   list( $aID ) = mysql_fetch_array( $result );
     282  list( $aID ) = mysqli_fetch_array( $result );
    296283
    297284  $query  = "INSERT INTO queue_messages " .
    298285            "SET analysisID = $aID, " .
    299             "message = '" . mysql_real_escape_string( $message ) . "'";
    300   $result = mysql_query( $query, $gLink );
     286            "message = '" . mysqli_real_escape_string( $gLink, $message ) . "'";
     287  $result = mysqli_query( $gLink, $query );
    301288  if ( ! $result )
    302289  {
    303     write_log( "$self: bad query: $query " . mysql_error( $gLink ) );
    304     return;
    305   }
    306 
    307   mysql_close( $gLink );
     290    write_log( "$self: bad query: $query " . mysqli_error( $gLink ) );
     291    return;
     292  }
     293
     294  mysqli_close( $gLink );
    308295}
    309296
     
    353340
    354341   // Get data from global GFAC DB
    355    $gLink = mysql_connect( $dbhost, $guser, $gpasswd );
    356    if ( ! mysql_select_db( $gDB, $gLink ) )
    357    {
    358       write_log( "$self: Could not select DB $gDB " . mysql_error( $gLink ) );
     342   $gLink = mysqli_connect( $dbhost, $guser, $gpasswd, $gDB );
     343   if ( ! $gLink )
     344   {
     345      write_log( "$self: Could not connect to DB $gDB " . mysqli_error( $gLink ) );
    359346      return;
    360347   }
     
    362349   // Update message and update status to 'FINISHED'
    363350   $query = "UPDATE analysis SET status='FINISHED', " .
    364             "queue_msg='" . mysql_real_escape_string( $message ) . "' " .
     351            "queue_msg='" . mysqli_real_escape_string( $gLink, $message ) . "' " .
    365352            "WHERE gfacID='$gfacID'";
    366353
    367    mysql_query( $query, $gLink );
     354   mysqli_query( $gLink, $query );
    368355   write_log( "$self: Status FINISHED and 'Finished...' message updated" );
    369356
     
    371358   $query  = "SELECT id FROM analysis " .
    372359             "WHERE gfacID = '$gfacID'";
    373    $result = mysql_query( $query, $gLink );
     360   $result = mysqli_query( $gLink, $query );
    374361   if ( ! $result )
    375362   {
    376       write_log( "$self: bad query: $query " . mysql_error( $gLink ) );
    377       return;
    378    }
    379 
    380    if ( mysql_num_rows( $result ) == 0 )
     363      write_log( "$self: bad query: $query " . mysqli_error( $gLink ) );
     364      return;
     365   }
     366
     367   if ( mysqli_num_rows( $result ) == 0 )
    381368   {
    382369//      write_log( "$self: can't find $gfacID in GFAC db" );
     
    384371   }
    385372
    386    list( $aID ) = mysql_fetch_array( $result );
     373   list( $aID ) = mysqli_fetch_array( $result );
    387374
    388375   $query  = "INSERT INTO queue_messages " .
    389376             "SET analysisID = $aID, " .
    390              "message = '" . mysql_real_escape_string( $message ) . "'";
    391    $result = mysql_query( $query, $gLink );
     377             "message = '" . mysqli_real_escape_string( $gLink, $message ) . "'";
     378   $result = mysqli_query( $gLink, $query );
    392379   if ( ! $result )
    393380   {
    394       write_log( "$self: bad query: $query " . mysql_error( $gLink ) );
    395       return;
    396    }
    397 
    398    mysql_close( $gLink );
     381      write_log( "$self: bad query: $query " . mysqli_error( $gLink ) );
     382      return;
     383   }
     384
     385   mysqli_close( $gLink );
    399386}
    400387?>
Note: See TracChangeset for help on using the changeset viewer.