PHP version: I've tried with both 5.1.2 and 5.1.3-dev
PDO version: Bundled, I think it's 1.0.2
MYSQL_PDO: I've tried with both 0.9 (on php 5.1.2) and 1.0.1 (on php 5.1.3-dev)
Hi, I'm having some difficulty with PDO's bindParam (and related) methods. It is easiest to see the problem with a small example.
<?php
try {
$db = new PDO(/*removed*/);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT id, name, description FROM recipe";
$stmt = $db->prepare( $sql );
$stmt->execute();
$res = $stmt->fetch();
print_r($res);
} catch(PDOException $e) {
die("PDO Error: ".$e->getMessage()."\n");
}
?>
gives
Array
(
[id] => 1
[0] => 1
[name] => Test 1
[1] => Test 1
[description] => This is my first test recipe, it was originally created to test the caching architecture but now can be anything.
[2] => This is my first test recipe, it was originally created to test the caching architecture but now can be anything.
)
However if I try to add some parameter bindings to the query it all falls down. Here's the same example modified.
<?php
try {
$db = new PDO(/*removed*/);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT id, name, description FROM recipe WHERE id=:id";
$stmt = $db->prepare( $sql );
$id = 1;
$stmt->bindParam(':id', $id);
$stmt->execute();
$res = $stmt->fetch();
var_dump($res);
} catch(PDOException $e) {
die("PDO Error: ".$e->getMessage()."\n");
}
?>
gives
bool(false)
I have tried using bindValue and passing an associative array into execute. I have also tried using non-named parameters but none of them seem to work.
I've tried it on multiple setups so I'm pretty sure it's something in my code. Anyone got any ideas?