3

I am using WindowsXP machine for the PHP pages I am developing. I am using PDO to connect to MySQL backend. In my development environment it works just fine but it silently stops processing in my CentOS 5.5 testing server. After some debugging, I found that it stops exactly at '$stmt->bindParams' section.

My statement is as follows:

$stmt = $dbh->prepare('SELECT * FROM MEMBERS WHERE ID=:what');

echo 'statement prepared'; //debug

$stmt->bindParam('what', $enteredid);

echo 'parameters bound'; //debug

also tried

$stmt->bindParam('what', $enteredid, PDO::PARAM_STR, 255);

both works in my development machine but it stops in my test server.

I can only see 'statement prepared' and nothing happens.

Also tried the page in hosting environment. Same thing happens.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Deepak Shrestha
  • 773
  • 2
  • 9
  • 25
  • See what messages you get with `error_reporting(E_ALL)`. – lonesomeday Jan 29 '11 at 10:09
  • Also http://stackoverflow.com/questions/3726505/how-to-squeeze-error-message-out-of-pdo – Pekka Jan 29 '11 at 10:10
  • error_reporting(E_ALL) doesn't show anything. Also tried to set in php.ini file. Nothing shows. By the way this statement is inside the try-catch. Seems no exception is thrown. Any suggestion? – Deepak Shrestha Jan 29 '11 at 10:33
  • @Pekka I have tried using $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); but result is still the same. It works in my development machine but fails in test server. No output whatsoever. – Deepak Shrestha Jan 29 '11 at 11:43
  • @Deepak did you try ERRMODE_EXCEPTION as outlined in the linked question? – Pekka Jan 29 '11 at 11:48
  • @Pekka I have tried also modifying the statement to remove the bindParam thing like this $stmt = $dbh->prepare('SELECT * FROM MEMBERS WHERE ID=' . "'" . $enteredid . "'");. so far this works fine but statement won't execute. Any idea? – Deepak Shrestha Jan 29 '11 at 11:53
  • @Deepak did you try ERRMODE_EXCEPTION? – Pekka Jan 29 '11 at 11:54
  • 1
    @Pekka I just tried ERRMODE_EXCEPTION. Only this made PDO spit out the exception. I got "base table does not exist" error. It's due to CASE SENSITIVITY in *nix machine. My table was nambed 'members' while I used 'MEMBERS' in my select statement. In windows it went fine but it stopped in my test server due to case mismatch. It is solved now. Thanks for your help. Regards – Deepak Shrestha Jan 29 '11 at 12:01

2 Answers2

1

When you call bindParam() don't you need to pass ':what' as the placeholder to bind to instead of 'what'? Not sure why this would work on Windows and not Linux though...

Jeremy
  • 2,651
  • 1
  • 21
  • 28
1

Old, but someone might find this useful

The correct code is:

$stmt = $dbh->prepare('SELECT * FROM MEMBERS WHERE ID=:what');

echo 'statement prepared'; //debug

$stmt->bindValue(':what', $enteredid);

echo 'parameters bound'; //debug

$stmt->execute();
Diego Vieira
  • 1,150
  • 2
  • 13
  • 31