mysql pdo binding with less than operator

tyuret
tyuret used Ask the Experts™
on
I have a select function like this

function selectsqlpn($sql,$arr) {
      global  $dbpdo;
      $q = $dbpdo->prepare($sql);
      $q-> execute($arr);
      $r = $q ->fetchAll();
      return $r;
}

And I make the query like this

$valreplace=6;
$sql="Select * from TABLE where A<? ";
$res=selectsqlpn($sql,$valreplace);

The result is equal to
$sql="Select * from TABLE where A<'6' ";

But I want it like this
$sql="Select * from TABLE where A<6 ";

So how will I bind it?

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You can use BindParam for that

This is an example from PHP Manual

<?php
/* Execute a prepared statement by binding PHP variables */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < ? AND colour = ?');
$sth->bindParam(1, $calories, PDO::PARAM_INT);
$sth->bindParam(2, $colour, PDO::PARAM_STR, 12);
$sth->execute();
?>

Open in new window


http://php.net/manual/en/pdostatement.bindparam.php

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial