RO Nerio
RO Nerio

Reputation: 21

[DB2 for i5/OS]SQL0104 - Token ? was not valid. Valid tokens: ) ,., SQL state 37000

I have troubles whit a DB2 query:

I'm using PHP and SQL Server to build db2 querys, actualy I have 30 query's working perfectly.

Yersterday I added a new query and it doesnt works and I really don't know why.

It's the same code and I made this to test "SELECT COUNT(F61AÑO) AS BALANCE FROM BUSRCDFX.FIP61"

and still giving this:

Warning: odbc_exec(): SQL error: [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0104 - Token � was not valid. Valid tokens: ) ,., SQL state 37000 in SQLExecDirect in C:\AppServ\www\ficosys\pcoInterfazFicoCom.php on line 80

Te code in PHP:

try
{
//here is where the query is building       
    $conn = OpenConnectionIM();  
        $tsql = "
            SELECT 
                id
            ,   '
                EXEC ' + Data_Function + ' ''CD77'' ' + ', ' + CAST(id AS VARCHAR) +'
                '
            ,   (SELECT COUNT(Concept_name) FROM [paco_PAL_tab]) AS lmt
            ,   Concept_Name
            FROM [paco_PAL_tab] 

            ORDER BY id ASC
        ";
        $getNames = sqlsrv_query($conn, $tsql);                                                     
        if ($getNames == FALSE)  
            die("Error: ".sqlsrv_errors());  
            $productCount = 0;  

        while($row = sqlsrv_fetch_array($getNames, SQLSRV_FETCH_BOTH))  
        {    
            $Query = $row[1];                                                           
            $getNames2 = sqlsrv_query($conn, $Query); 
            if ($getNames2 == FALSE)  
                die("Error: ".sqlsrv_errors());  
            $productCount2 = 0;         

            while($row2 = sqlsrv_fetch_array($getNames2, SQLSRV_FETCH_BOTH)){
                $connDB2 = OpenConnectionDB2() ;
               //clean the text
                $sqlDB2 = "  ";
                $sqlDB2 = $row2[0];
                $sqlDB2 = str_replace('¬¬',"'",$sqlDB2);
                $sqlDB2 = str_replace('�',"'",$sqlDB2);
                $sqlDB2 = str_replace(')  ',")",$sqlDB2);
                echo '<p> Query | </p>'.$sqlDB2 . $Query.'<br />';      

                //exec the query in BD2
                if($sqlDB2 !== 'TBD'){
                    try{    
                        $getNamesDB2 = odbc_exec($connDB2, $sqlDB2);
                    }
                    catch (Exception $e)
                    {
                            echo '<td  data-title="Query" id="qry'.$productCount2.'">'.'IBM tiene problemas : '. $sqlDB2.'</td>';
                    }   
                    ini_set('max_execution_time', 120);
                        while( $rowDB2 = odbc_fetch_array($getNamesDB2) ) { 
                        //  echo '<td  data-title="Query" id="qry'.$productCount2.'">' . $sqlDB2 . '</td>';                                                                         
                            if(es_negativo($rowDB2['BALANCE'])){$colorspan = 'style="color:#fc4b4b !important; text-shadow:1px 1px 1px #ffffff!important;"';}
                            else{$colorspan = 'stye=""';}
                            echo '<td  data-title="BALANCE" id="qry'.$productCount2.'" '.$colorspan.'>' . " <strong><h3>$".number_format($rowDB2['BALANCE'],2,".",",") .'</strong></h3></td>';
                            //echo '<td  data-title="balance">' . $rowDB2['BALANCE']. '</td>';
                            /*
                            $tsqlInterfaz = "
                                EXECUTE spa_CargaRealBPCS
                                        @RubroPaco      = '".$row[3]."'
                                    ,   @Cuenta         = '".str_replace('X',"",$rowDB2['PTLCC'])."' 
                                    ,   @descCue        = '".$rowDB2['PTLCC']."'
                                    ,   @anioPeriodo    = '".$rowDB2['YEAR']."'
                                    ,   @MontoMes       = '".$rowDB2['BALANCE']."'
                                    ,   @idTran         = '".$idTran."'
                            ";
                            echo $tsqlInterfaz.'<br />';
                            $connInterfaz = OpenConnectionIM();
                            sqlsrv_query($connInterfaz, $tsqlInterfaz);
                            if ($getNames2 == FALSE)
                                die("Error: oh no ".sqlsrv_errors());
                            $productCount2 = 0;
                            $productCount2++;
                            */
                        }   
                }else{
                    echo '<td  data-title="Query" id="qry'.$productCount2.'"><h3> TBD | '.$sqlDB2 .' </h3></td>';
                }
            }
        }

I hope someone has already fixed it

Upvotes: 0

Views: 4224

Answers (1)

RO Nerio
RO Nerio

Reputation: 21

Well I already resolved it the problem was the coding I just changed UTF-8 to ANSI. And then this :

$getNamesDB2 = odbc_exec($connDB2, utf8_decode($sqlDB2));

Apparently the "ñ" at column name was the whole problem >.<

Upvotes: 1

Related Questions