0

I want to execute the following query on mysql DB, using PHP-PDO.
SELECT count(id) FROM view_id WHERE id=@id and id_a='1' and id_b='1' and id_c='3' and id_d='2' However when I run on the database it executes nice, and gives me a result. But when executing with php - PDO it gives error, by the way no error message, just stops the webpage deployment. Any help is really appreciated.

Thanks,

digitai
  • 1,870
  • 2
  • 20
  • 37
  • 2
    Any code is appreciated as well. Unless you want us to read your code and mind remotely, for which the software doesn't exist yet. But I heard google is working on it. – N.B. Jun 19 '13 at 14:08
  • 2
    [PDO query fails but I can't see any errors. How to get an error message from PDO?](http://stackoverflow.com/a/15990858/285587) – Your Common Sense Jun 19 '13 at 14:29

1 Answers1

-2

It's hard to be sure without seeing the actual code used to call it, but right off, you have the wrong parameter marker in yoru SQL. PDO uses a colon for named parameter, e.g. "id=:id". You have an at symbol, which could cause the problem.

As for the error reporting, check that your error mode is set to something sensible.

Peter Geer
  • 1,132
  • 1
  • 6
  • 11
  • I'm usung this code:$query_header=$dbh->query(SELECT count(id) FROM view_id WHERE id='5' and id_a='1' and id_b='1' and id_c='3' and id_d='2') – digitai Jun 19 '13 at 14:37
  • If instead of 'query' I use 'prepare' in the PDO statement, no error, but when executing I get error. Also my error_mode is set to ERRMODE_EXCEPTION, but when executed just get a blank page with no source content at all. – digitai Jun 19 '13 at 14:46
  • Prepare doesn't actually perform the query before it is executed, it just compiles it, so you wouldn't get any errors from exceptions, only syntax errors which would stop it from compiling – TheEnvironmentalist Jun 19 '13 at 16:37
  • Use `try` and `catch` to catch the exception – TheEnvironmentalist Jun 19 '13 at 16:44