lundi 6 juillet 2015

PHP + MSSQL using PDO with Named Parameters not '?'

I'm about to commence building a site using mssql and php.

I plan to use PDO's, however, as I currenlty believe its not possible to use named parameters.

Currently in MySQL I would use named placeholders in my query as such;

$sql = "SELECT *
        FROM table
        LIMIT :numRows";

$st = $this->conn->prepare( $sql );
$st->bindValue( ":numRows", $numRows, PDO::PARAM_INT );

However when using MSSQL;

$sSQLInsert = "SELECT TOP ? *
    FROM table";

$aParams = array($iLimit);

$st = sqlsrv_query($dbhandle, $sSQLInsert, $aParams)){}

My worry appears when I have many parameters that need to be bound. Managing the order of them and dancing back and forth between query-parameters doesnt seem ideal.

So my question; is it posible to use named placeholders with MSSQL?

Aucun commentaire:

Enregistrer un commentaire