Skip to content
Advertisement

SQLSTATE[IMSSP]: Tried to bind parameter number 65536. SQL Server supports a maximum of 2100 parameters

I want to ask something what error is this. I want to display report book to PHP but the result showing like in picture

Error

Here is my report book:

public function GetReportBook($id_book, $TanggalStart, $TanggalEnd)
    {
        // select all query
        try {
            require_once 'Database.php';
            $sqlsrvquery = (" EXEC [dbo].[GetReportBook] @id_book=id_book, @TanggalStart=TanggalStart, @TanggalEnd=TanggalEnd");
            // prepare query statement
            $stmt = $this->conn->prepare($sqlsrvquery);
            $stmt->bindParam('id_book', $id_book, PDO::PARAM_STR);
            $stmt->bindParam('TanggalStart', $TanggalStart, PDO::PARAM_STR);
            $stmt->bindParam('TanggalEnd', $TanggalEnd, PDO::PARAM_STR);
            $stmt->execute();
            while($r = $stmt->fetch(PDO::FETCH_OBJ)) {
                print_r($r);
            }


        } catch (Exception $e) {
            print_r($e->getMessage());
        }
    }
}

and here is the result showing in ASP.NET:

ASP.NET

Advertisement

Answer

You need to consider the following:

  • You need to use named (:name) or question mark (?) parameter markers in the prepared statement.
  • You need to use an unambiguous datetime format (yyyymmdd in your case) for the value of :TanggalStart and :TanggalEnd parameters.

An example, based on your code:

public function GetReportBook($id_book, $TanggalStart, $TanggalEnd)
    {
        // select all query
        try {
            require_once 'Database.php';
            $sqlsrvquery = ("
               EXEC [dbo].[GetReportBook] 
                   @id_book = :id_book, 
                   @TanggalStart = :TanggalStart, 
                   @TanggalEnd = :TanggalEnd
            ");
            // prepare query statement
            $stmt = $this->conn->prepare($sqlsrvquery);
            $stmt->bindParam(':id_book', $id_book, PDO::PARAM_STR);
            $stmt->bindParam(':TanggalStart', date('Ymd', strtotime($TanggalStart)), PDO::PARAM_STR);
            $stmt->bindParam(':TanggalEnd', date('Ymd', strtotime($TanggalEnd)), PDO::PARAM_STR);
            $stmt->execute();
            while($r = $stmt->fetch(PDO::FETCH_OBJ)) {
                print_r($r);
            }
        } catch (Exception $e) {
            print_r($e->getMessage());
        }
    }
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement