ibase_query(): Dynamic SQL Error SQL error code = -104 Token unknown

739 views Asked by At

I've been trying to do a search filter and this error continue to appear, can someone help me out?

{

    require_once('conn.php');

    
    $idata = $_POST["idata"];
    $fdata = $_POST["fdata"];

    $sql = "Select TOP 10* from cadcli where dtcad between $idata and $fdata";
    $query = ibase_query($dbh,$sql) or die (ibase_errmsg());
    while ($row = ibase_fetch_object($query)) {
        echo $row->COLUNA1."n";}
    ibase_free_result($query);
    echo "$query";
    ibase_close($dbh);


}
1

There are 1 answers

0
Mark Rotteveel On BEST ANSWER

The problem is that Firebird doesn't know the keyword TOP. The equivalent in Firebird 2.5 and earlier is FIRST. Since Firebird 3, you can also use the SQL standard FETCH.

Using FIRST:

select first 10 * from cadcli ... 

Using FETCH:

select * from cadcli ... fetch first 10 rows only

Please be aware that without an ORDER BY, the order is not deterministic.

I also notice that you are doing string interpolation in your query, which makes it vulnerable to SQL injection. I recommend that you switch to using prepared statements with parameters (see ibase_prepare and ibase_execute).