bindParam in database classes

bindParam in database classes

csdatumcsdatum Posts: 30Questions: 10Answers: 0

I need to perform multiple queries consecutively with slightly different bound values. Normally I would use PHP PDO's $stmt -> bindParam().

I tried using $query -> where( $key, ':placeholder', '=', false ) and repeatedly re-calling $query -> bind( ':placeholder', $val ) before each $query -> exec() call, however the where() call wrapped the ':placeholder' in square brackets.

Is there any way to execute a query multiple times with a different bound value?

Answers

  • allanallan Posts: 62,110Questions: 1Answers: 10,185 Site admin

    No sorry - with the database classes provided with Editor you would need to create a new Query instance for each query you want to execute. They cannot be reused.

    Depending on what you want to do, you can access the PDO instance that the database class is using - $db->resource(). Then you can use PDO directly (assuming this is outside of the Editor class).

    Allan

  • csdatumcsdatum Posts: 30Questions: 10Answers: 0

    Would it be likely in a future release for $query->where() to optionally not wrap the value in square brackets? I believe this would be an easy fix and would open up lots of possibilities.

  • allanallan Posts: 62,110Questions: 1Answers: 10,185 Site admin

    It shouldn't be using square brackets at all - unless you are using SQL Server as it uses square brackets for quoting field names?

    Allan

  • csdatumcsdatum Posts: 30Questions: 10Answers: 0

    Yeah exactly, we're using SQL server and the _protect_identifiers() function in /php/Database/Query.php always adds them in.

This discussion has been closed.