Hi guys,
when viewing a node as an authenticated user with permissions granted by the Node View Permissions, I get the following error (when viewing the node as user 1, no problems):

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (c.nid = '283') AND (c.status = '1')' at line 2: SELECT COUNT(*) AS expression FROM {comment} c INNER JOIN {node} n ON n.nid = .nid WHERE (c.nid = :db_condition_placeholder_0) AND (c.status = :db_condition_placeholder_1) ; Array ( [:db_condition_placeholder_0] => 283 [:db_condition_placeholder_1] => 1 ) i PagerDefault->execute() (linje 74 af /<mypath>/includes/pager.inc).

The error goes away when disabling the Node View Permissions module.

The error has started appearing after upgrading PHP to v. 5.6.11 on a FreeBSD server.

The error is not present on a dev site running PHP v. 5.5.9 which makes me think it is related.

MySQL is v. 5.5.44

The site has SSL enabled (rewrites alias domains in .htaccess).

Here's a list of the enabled modules (Drupal v. 7.39):

 Package           Name                                           Version       
 Access control    Node view permissions (node_view_permissions)  7.x-1.5       
 Administration    Administration menu (admin_menu)               7.x-3.0-rc5   
 Administration    Administration menu Toolbar style              7.x-3.0-rc5   
                   (admin_menu_toolbar)                                         
 Administration    Module filter (module_filter)                  7.x-2.0       
 Chaos tool suite  Chaos tools (ctools)                           7.x-1.9       
 Chaos tool suite  Page manager (page_manager)                    7.x-1.9       
 Core              Block (block)                                  7.39          
 Core              Color (color)                                  7.39          
 Core              Comment (comment)                              7.39          
 Core              Content translation (translation)              7.39          
 Core              Contextual links (contextual)                  7.39          
 Core              Dashboard (dashboard)                          7.39          
 Core              Database logging (dblog)                       7.39          
 Core              Field (field)                                  7.39          
 Core              Field SQL storage (field_sql_storage)          7.39          
 Core              Field UI (field_ui)                            7.39          
 Core              File (file)                                    7.39          
 Core              Filter (filter)                                7.39          
 Core              Help (help)                                    7.39          
 Core              Image (image)                                  7.39          
 Core              List (list)                                    7.39          
 Core              Locale (locale)                                7.39          
 Core              Menu (menu)                                    7.39          
 Core              Node (node)                                    7.39          
 Core              Number (number)                                7.39          
 Core              Options (options)                              7.39          
 Core              Overlay (overlay)                              7.39          
 Core              Path (path)                                    7.39          
 Core              PHP filter (php)                               7.39          
 Core              RDF (rdf)                                      7.39          
 Core              Search (search)                                7.39          
 Core              Shortcut (shortcut)                            7.39          
 Core              System (system)                                7.39          
 Core              Taxonomy (taxonomy)                            7.39          
 Core              Text (text)                                    7.39          
 Core              Update manager (update)                        7.39          
 Core              User (user)                                    7.39          
 Fields            Entity Reference (entityreference)             7.x-1.1       
 Fields            Field Permissions (field_permissions)          7.x-1.0-beta2 
 Fields            Link (link)                                    7.x-1.3       
 Helper modules    cfdp_uf (cfdp_uf)                              7.x-1.0       
 Other             Backup and Migrate (backup_migrate)            7.x-2.8       
 Other             Disable breadcrumbs (disable_breadcrumbs)      7.x-1.3       
 Other             Email Registration (email_registration)        7.x-1.2       
 Other             Entity API (entity)                            7.x-1.6       
 Other             Entity tokens (entity_token)                   7.x-1.6       
 Other             Masquerade (masquerade)                        7.x-1.0-rc7   
 Other             Prepopulate (prepopulate)                      7.x-2.0       
 Other             Profile2 (profile2)                            7.x-1.3       
 Other             Profile2 pages (profile2_page)                 7.x-1.3       
 Other             Profile2 Registration Path (profile2_regpath)  7.x-2.0-beta3 
 Panels            Panels (panels)                                7.x-3.5       
 Rules             Rules (rules)                                  7.x-2.9       
 Rules             Rules Link (rules_link)                        7.x-1.1       
 Rules             Rules Scheduler (rules_scheduler)              7.x-2.9       
 Rules             Rules UI (rules_admin)                         7.x-2.9       
 User interface    Wysiwyg (wysiwyg)                              7.x-2.2       
 Views             Views (views)                                  7.x-3.11      
 Views             Views Accordion (views_accordion)              7.x-1.1       
 Views             Views Field View (views_field_view)            7.x-1.1       
 Views             Views UI (views_ui)                            7.x-3.11

I am not at all sure that Node View Permissions is the culprit - but hoping you can lead me on the track.

Comments

benjamin_dk created an issue. See original summary.

sergei_semipiadniy’s picture

Hi Benjamin,
Trouble happens at line 127 in node_view_permissions module "$query->join('node', 'n', 'n.nid = ' . key($tables) . '.nid');".

redsky’s picture

I am not sure if the cause is the identical but I I have the same error and I see the same problem in the generated SQL - a missing alias here:

INNER JOIN {node} n ON n.nid = .nid

I haven't had any version changes in PHP or MySQL like the ones noted by benjamin_dk. I am also using the Node View Permissions module. I have a another content type that is configured similarly that does not produce this error. I'll report back if I learn more.

redsky’s picture

Sorry about that, this turned out to be a problem with the nodeaccess module. When I turned off Node View Permissions the problem persisted however when I turned off Nodeaccess everything worked. And it still worked when I turned back on the Node View Permissions module.

mortenh’s picture

StatusFileSize
new1.14 KB

Hi
We just had the same problem after a php 5.6 upgrade.
The attached patch solved the problem. Can't really explain why and it might be completely wrong :)
No php 5.6 migration docs mentions anything about the internal array pointer being moved differently.

nerdoc’s picture

I have the same error, but have no nodeaccess module installed, so that can't be the problem here. But node_view_permissions is installed and enabled here.

The problem started at Sept 1 2015 10:41 - but there were no module updates directly before that timestamp.

And I can confirm that patch #5 fixes the problem here.

Lonnytunes’s picture

Status: Active » Needs review
benjamin_dk’s picture

Thanks for your help everybody - mhbellcom, your patch #5 works for me too!

Sorry for not replying sooner - my notifications were turned off :-/

ikeigenwijs’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that patch #5 fixes the problem here.
Thats 3 positive reviews --> changed status

delaBruyne’s picture

I can confirm that patch #5 fixes my problem too!
Thank you :)

stewest’s picture

Thanks! I can confirm that patch #5 fixes my problem too!

a.milkovsky’s picture

+1 for #5. Fixed for me.
Thank you.

xavier.g’s picture

The patch (#5) solved my issue too. Thanks !

hgoto’s picture

StatusFileSize
new807 bytes

The patch #5 works well also for me.

As mmhbellcom told, PHP 5.6 doesn't change the pointer behaviour and this should be a bug even with PHP 5.4 or 5.5. I tested and confirmed that there's no error with PHP 5.4 nor 5.5 but I don't understand why the current code works in PHP 5.5...

The patch #5 works well but we don't need to change some parts of code. Here is a simpler one. (The file's line break code is not correct but I avoided to change it here.)

qazema’s picture

Patch #5 and #14 works both.

drusite’s picture

An authenticated user can't see any comments on the Node View Permissions Content. What's the problem?

Marko B’s picture

Had the same problem since PHP upgrade. Solved with this patch.

drusite’s picture

It seems that these patches work only for some cases. In my case they didn't work.

hgoto’s picture

@drusite, thank you for your feedback. If possible, could you share me the steps to reproduce the situation they don't work?

hgoto’s picture

StatusFileSize
new860 bytes

My recognition for the cause was wrong. The array pointer is not changed by the `foreach` loop just before the error. So I changed the comment slightly. Only difference between this patch and the #14 is the comment.

hgoto’s picture

Status: Reviewed & tested by the community » Needs review
oleksiy’s picture

StatusFileSize
new672 bytes

Can't apply #14 and #20 patches. Got the following error:

(Stripping trailing CRs from patch; use --binary to disable.)
patching file node_view_permissions.module
patch: **** malformed patch at line 23:        foreach (node_view_permissions_get_configured_types() as $type) {

Have simplified and recreated it.

hgoto’s picture

Oleksiy, thank you for revising it.

jwineichen’s picture

#22 worked for me

bdlangton’s picture

Status: Needs review » Reviewed & tested by the community

#22 works for me.

bmango’s picture

#22 worked for me. Many thanks.

peter caritas’s picture

This patch works for me. The error only surfaced when I installed the site on a server running PHP 5.6.16 and mysql 5.6.31. Previously the error did not appear on a server running PHP 5.3.x and Mysql 5.5.50-cll.

However, the patch did not apply cleanly to 7.x-1.x-dev. I didn't try applying it to 7.x.15. But I think typically patches are made against dev so they can be committed?

ollie222’s picture

I've just come across this error using the forum and advanced forum modules on a PHP 5.6 server.

The patch in #22 applied to 7.x-1.5 has solved the issue for me so thanks for the patch and I'd like to see the patch committed.

citizenkepler’s picture

I have had the same issue with the PDO error on php 5.6 with the advanced forum module. I have applied #20's patch and this has resolved the issue for me as well.

signaltrace’s picture

Just chiming in - I ran into this same issue after upgrading to PHP 5.6. Patch #22 fixed it for me as well. Thanks!

Philou88’s picture

I got the problem after upgrading to PHP 5.6 in ".../includes/pager.inc (line 74)" and in ".../modules/forum/forum.module (line 716)".
Patch #22 fixed the 2 issues as well. Many Thanks!

p4trizio’s picture

#22 works for me too

fietserwin’s picture

+1 on #22. Please commit (and release a new version) or change the module maintenance status to "unsupported" or ""seeking new maintainer" to express that you don't maintain this module anymore.

krilo_89’s picture

Works for me, but saw a small spelling error: because.

+++ b/node_view_permissions.module
@@ -125,6 +125,9 @@ function node_view_permissions_query_node_access_alter(QueryAlterableInterface $
+      // because it can be NULL here.
helmo’s picture

Thanks, #5 works as expected.

aytee’s picture

Patch #5 worked for me. Thanks!

jdhildeb’s picture

Patch #22 worked for me. I'd like to echo what @fietserwin said - please commit (and release a new version) or change the module maintenance status to "unsupported" or ""seeking new maintainer" to express that you don't maintain this module anymore.

nikolabintev’s picture

Patch #22 works for me. key() returns NULL, because at the end of loop, internal pointer is on the end, and that's how it works. The query is the default pager query for comments.

hongpong’s picture

#22 worked for me. This needs to be committed! Was definitely triggered by updating to PHP5.6.

Anonymous’s picture

#22 patch worked for me, please commit.

blainelang’s picture

Yes, please commit this as it prevented access for user access on a clients site's forum and it was not easy to track the SQL error down to this issue.

adci_contributor’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Hi, guys!

Sorry, we did not answer for a long time. Thank you for your feedback.
We added a patch and released a new version.
Please check and test it.

adci_contributor’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.