custom ssp script problem and question

custom ssp script problem and question

bbrindzabbrindza Posts: 316Questions: 73Answers: 1

I need to get additional data from another DB2 table based on the value of main ssp DB2 table.

I am receiving a PHP syntax error. Prepare failed - Get Full Name from USERTAB in ssp_WorkOrderManagement.phpToken ) was not valid. Valid tokens: [. SQLCODE=-104

I am going about this in the correct way?

<?php

include('i5db2connect.php');

if (isset($_POST['locationCode'])) {
    $locationCode = $_POST['locationCode'];
}

// DB table to use
$table = 'NWFF.MTCTRAN ';

// Used for optional WHERE clauses that will be appended to the SQL string
//$extraWhere = "";

// Table's primary key
$primaryKey = array('TNLOC', 'TNINTR');

// Array of database columns
$columns = array();

$columns[] = array( 'db' => 'TNTYPE','dt' => 'order_type' );  

$columns[] = array( 'db' => 'TNORDN',   'dt' => 'order_number' );

$columns[] = array( 'db' => 'TNCODE','dt' => 'machine_code' );
      
$columns[] = array( 'db' => 'TNTSK#','dt' => 'task_number' );

$columns[] = array( 'db' => 'TNATEM', 'dt' => 'assigned_to' ,
    

  'formatter' => function( $d, $row ) {
        
        if(trim($d) !== "" ){ 
                    
               $sql = "SELECT * FROM NWFF.USERTAB WHERE UTUSR10 = '$d'";
                      
              $results = db2_prepare( $connection, $sql )
                              or die("<br>Prepare failed - Get Full Name from USERTAB in ssp_WorkOrderManagement.php". db2_stmt_errormsg());
                            
              db2_execute( $results )
                            or die("<br>Execute failed - Get Full Name from USERTAB in ssp_WorkOrderManagement.php". db2_stmt_errormsg());
                            
                  if (false !== ($USERTABrow = db2_fetch_assoc($results))) {
                                
                            return ucwords(trim($USERTABrow['UTNME']));
                                
                         }else{
                                
                                    return 'Name Not Found in USERTAB';
                          }
                  }else{
                    return 'Not Assigned';
        }
    }
);
$columns[] = array( 'db' => 'TNTMLS','dt' => 'lost_time' );
$columns[] = array( 'db' => 'TNSHFT','dt' => 'shift_number' );

require( 'ssp.class.php' );

echo json_encode(
    SSP::simple( $_GET, $connection, $select, $table, $primaryKey, $columns, $extraWhere)
    );

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    $connection presumably comes from your i5db2connect.php include? If so, and you want to access it in a PHP function, you need to make it accessible using the use statement - PHP docs.

    For example:

    'formatter' => function( $d, $row ) use ($connection) {
    

    Allan

  • bbrindzabbrindza Posts: 316Questions: 73Answers: 1

    That makes sense. Thanks Allan

Sign In or Register to comment.