Link to home
Start Free TrialLog in
Avatar of andretty76
andretty76

asked on

Consultation in asp works but in php does not work

QUERY in asp works but in php does not work , I NEED THAT THIS QUERY WORKS IN PHP
The code php is this

$conn = odbc_connect('ANDRES','AFCORTES','ASrds5a');

$nrows=0;

if ($conn)
{
$sql =  "SELECT *  FROM CCOP2XBDT.F5Z7501  WHERE $AVMCU = '445000';
 
//this function will execute the sql satament
$result=odbc_exec($conn, $sql);

echo "<table  align=\"center\" border=\"1\" borderColor=\"\" cellpadding=\"0\" cellspacing=\"0\">\n";
echo "<tr> ";
// -- print field name
$colName = odbc_num_fields($result);
for ($j=1; $j<= $colName; $j++)
{
echo "<th  align=\"left\" bgcolor=\"#CCCCCC\" > <font color=\"#990000\"> ";
echo odbc_field_name ($result, $j );
echo "</font> </th>";
}
$j=$j-1;
$c=0;
// end of field names
while(odbc_fetch_row($result)) // getting data
{
 $c=$c+1;
 if ( $c%2 == 0 )
 echo "<tr bgcolor=\"#d0d0d0\" >\n";
 else
 echo "<tr bgcolor=\"#eeeeee\">\n";
   for($i=1;$i<=odbc_num_fields($result);$i++)
     {        
       echo "<td>";
       echo odbc_result($result,$i);
       echo "</td>";        
       if ( $i%$j == 0 )  
           {
           $nrows+=1; // counting no of rows    
         }  
     }
   echo "</tr>";
}

echo "</td> </tr>\n";
echo "</table >\n";
// --end of table  
if ($nrows==0) echo "<br/><center> Sin datos $month  que concuerden con su busqueda</center>  <br/>";
else echo "<br/><center> Total Records:  $nrows </center>  <br/>";
odbc_close ($conn);

}
else echo "odbc not connected <br>";
?>

THE CODE ASP IS THIS

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/PERRITOS.asp" -->
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "      445000"
If (Request("MM_EmptyValue") <> "") Then
  Recordset1__MMColParam = Request("MM_EmptyValue")
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_PERRITOS_STRING
Recordset1.Source = "SELECT *  FROM CCOP2XBDT.F5Z7501  WHERE $AVMCU = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

I NEED HELP ME

THE MISTAKE IN PHP IS THIS

Warning: odbc_exec(): SQL error: [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0104 - Token = was not valid. Valid tokens: ( + - ? : DAY NOT RRN CASE CAST CHAR DATE DAYS HASH HOUR LEFT., SQL state 37000 in SQLExecDirect in c:\appserv\www\new_intra\odbc\funciona.php on line 15

Warning: odbc_num_fields(): supplied argument is not a valid ODBC result resource in c:\appserv\www\new_intra\odbc\funciona.php on line 20

Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in c:\appserv\www\new_intra\odbc\funciona.php on line 30
 

ASKER CERTIFIED SOLUTION
Avatar of dr_dedo
dr_dedo
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In you ASP code, you are replacing ' with ''.

Recordset1.Source = "SELECT *  FROM CCOP2XBDT.F5Z7501  WHERE $AVMCU = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"

So, the PHP equivalent would be to use the str_replace function

$new_value = str_replace("'", "''", $old_value);

This will do the same as the Replace() function you used in ASP.


I would like to see the EXACT sql statement that is attempting to be used.

Before the odbc_exec() statement can you ...

echo ">>>$sql<<<";

and then view-source on the results page and cut and paste everything between >>> and <<<.

DO NOT SIMPLY CUT AND PASTE FROM THE BROWSER WINDOW AS THIS IS A VIEW OF THE DATA NOT THE DATA!!!!!! Browsers do all sorts of things to data (remove spaces, interpret values as symbols, etc).


The purpose of the echo is to help you diagnose the problem. It is NOT a solution. Yet!
Can you try removing the spaces from either side of the = sign?

Can you try replacing = with the word EQUALS