0

The query below is running well and runs quite fast for what it does. However it is displaying some very strange behaviour as outlined below.

However in PHP it seems to decide by itself which ids it will work for. I am certain that the code is correct. I am using PDO in PHP and binding the variables as required.

So for instance if I pass it the author_id 600 it will work, but if I pass it the author_id 2 it won't work and brings back no records. But if I echo the query and paste it into MySQL and run it, it works for both the ids. It would seem that the PDO is failing to bind the variable on some ids. I have echoed the id variable and it does indeed contain the proper id.

Has anyone else experienced this behaviour? I find it very very unusual.

SELECT
GROUP_CONCAT(a.author_id) AS author_ids
FROM
references_final AS rf
INNER JOIN (reference_authors AS ra INNER JOIN authors_final AS a ON (ra.author_id = a.author_id))
ON (rf.reference_id = ra.reference_id)
GROUP BY rf.reference_id HAVING :author_id IN (author_ids) 
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
jiraiya
  • 977
  • 4
  • 13
  • 34
  • 2
    Please reduce your problem to the bare minimum and give it a more descriptive title. – hakre Sep 28 '11 at 11:15
  • Have you dumped the queries for both IDs? – markus Sep 28 '11 at 11:36
  • Indeed I have dumped them for both. They both look the same as above but as I am using the PDO bindparam I cannot actually dump the value in a query string but if the query is the same and the dump of the author_id variable is the same then they both should be identical I would have thought. – jiraiya Sep 28 '11 at 11:41
  • I imagine this issue is related to a [previous post](http://stackoverflow.com/questions/5457471/mysql-in-list-only-validates-first-id-in-list-maybe-a-blob-issue/5457653) related to your use of the `in` operator. – jswolf19 Sep 28 '11 at 15:17

1 Answers1

0

Hey I am having the same problem With BindParam and ID value in my PDO Statement

$retrieveUsersToken = $dataBase->prepare('SELECT TheUsersTable.token AS token, TheUsersTable.myID AS myID, 
FROM TheUsersTable INNER JOIN TheCategoryListTable ON TheUsersTable.myID = TheCategoryListTable.userID 
WHERE TheUsersTable.myID != :userID AND TheCategoryListTable.category = :category');

$retrieveUsersToken->bindParam( ':category', $_POST['category'], PDO::PARAM_STR);
$retrieveUsersToken->bindParam( ':userID', $_POST['creatorID'], PDO::PARAM_INT);

myID != userID never works neighter does TheCategoryListTable.category = :category when :category contain space Looks like the Inner Join is creating troube in both our situations.

It's not really an answer but maybe binValue works better.

Nicolas Manzini
  • 8,379
  • 6
  • 63
  • 81