skip to Main Content

I have a prepared statement built inside a class:

function reader($ser)
    {
        $pstmt=odbc_prepare($this->conn,'SELECT TOP 1 "name"
        FROM '.$this->table.' WHERE 
        "surname" LIKE ? ');        
        return odbc_execute($pstmt,array("$ser"));  
    }

And gets its $ser through a post

$serTab=$product->reader($ser);

Example $ser :

$ser=' '3221252'';

When it comes to displaying values these functions return nothing (but they are working with odbc_exec):

while(odbc_fetch_row($serTab)) 
 { 
 for($i=1;$i<=odbc_num_fields($serTab);$i++) 
 {
echo odbc_result($serTab,$i);                       
 }
 }

Are there any alternatives for these functions? Why it doesn’t return anything with obdc_execute?How do I fix this?

Can’t use PDO because of this error:

Conversion of parameter/column (5) from data type NVARCHAR to ASCII
failed

I have no authorization to make changes on database, hence on data types.DBMS: SAP Hana

2

Answers


  1. Chosen as BEST ANSWER

    fixed it by adding

    $ser=str_replace(array("'", "'"," "),"",$ser) 
    

    before

    odbc_prepare
    

    and changed

     return odbc_execute($pstmt,array("$ser")); 
    

    to

     return odbc_execute($pstmt,array($ser));  
    

  2. odbc_execute just returns a boolean to indicate
    success or failure. What you need to return is $pstmt:

    function reader($ser)
    {
        $pstmt = odbc_prepare($this->conn, 'SELECT TOP 1 "name"
            FROM '.$this->table.' WHERE 
            "surname" LIKE ? ');        
        if(!odbc_execute($pstmt, array("$ser")))
            die('odbc_execute failed');
        return $pstmt;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search