What's wrong with my prepared SQL statement?
I'm new to using PDO and prepared statement so if I'm doing this blatantly wrong please let me know :)
I have the following code:
$stmt = $this->_dbh->prepare( '(SELECT folder_id, "y" AS "has_access", access_type FROM groups_users AS gu LEFT JOIN folders_groups AS fg ON gu.group_id = fg.group_id WHERE user_id = :user_id)
UNION
(SELECT folder_id, has_access, access_type FROM folders_users WHERE user_id = :user_id AND has_access = :yes)' );
$stmt->bindValue( ':user_id', $this->_user_id, PDO::PARAM_INT );
$stmt->bindValue( ':yes', self::YES, PDO::PARAM_STR );
$stmt->execute();
$folders = $stmt->fetch( PDO::FETCH_ASSOC );
and if I do:
print_r($this->_dbh->errorInfo());
print_r($folders);
$folders is FALSE and my errorInfo() returns:
Array ( [0] => 00000 [1] => [2] => )
Which from my understanding of it means there's no errors. I tried replacing my :user_id and :yes with the values and I don't get errors. The result is empty but my fetch call still returns 开发者_如何学JAVAfalse (which the documentation says that it failed) when I'm expecting an empty array.
Thanks for any help :)
A fetch call which returns false is not an error condition - it just means there's no data to fetch. e.g. your query returned no data. What does $stmt->rowCount()
return?
精彩评论