0

I'm new to php and pdo. I have the following code.

$buildFormId = 1;
$query = $pdo->prepare("select * from WebsiteBuildForm where id=:id");
$query->bindParam(':id', $buildFormId, PDO::PARAM_INT);
$query->execute();

if ($query->rowCount() == 0){
    echo "found nothing for ".$buildFormId;
    exit;
}

In this case I get the message that nothing was found. However if change the code to this, it works.

$buildFormId = 1;
$query = $pdo->prepare("select * from WebsiteBuildForm where id=".$buildFormId);
$query->execute();

From the examples for pdo that I've seen the first code block "should" work. Any idea what I'm doing wrong? Thanks.

9
  • Does the PDO query work if you remove PDO::PARAM_INT? Apr 28, 2016 at 15:22
  • no. I've also tried it without the bindParam line instead using ? in the query and an array in the execute call. Apr 28, 2016 at 15:24
  • your code worked for me, so you've got some typo and this question is not a real one. Apr 28, 2016 at 15:29
  • @YourCommonSense the fact you can't reproduce doesn't mean there is no problem... It may be specific to his config or something else...
    – Random
    Apr 28, 2016 at 15:32
  • 2
    Found my answer. stackoverflow.com/questions/3828215/… Changed the FreeTDS version from 8.0 to 7.2 and parameters work now. Apr 28, 2016 at 16:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.