Possible Root Cause Analysis for “Column ‘link_id’ cannot be null” Error
-
This is a follow-up to a topic created 6 months ago (and now closed for replies) made by another user, titled: “Fatal Error: ‘link_id cannot be null’ in Track The Click Plugin on PHP 8+”.
I’m running into what appears to be the same issue, and asked Claude Code to point to where the issue may be stemming from, in case it helps speed up development of a fix.
For now I’ve disabled the plugin on my site 🙁In case the below helps:
Potential Issue #1: Query Logic Mismatch
For non-post pages (post_id = 0), there’s an inconsistency:
- Initial lookup (line 156): Queries using post_id = 0 AND page_url = %s AND url = %s
- Re-query after insert (line 164): Only uses post_id = %d AND url = %s (missing page_url)
This means the re-query may not find the link that was just inserted, leaving link_id as NULL.
Potential Issue #2: Missing Error Handling
The code doesn’t check if the database insert (line 159) succeeded. If it fails, the re-query returns NULL, but the code proceeds to insert NULL into the track_the_click_hit table → database error.
Potential Issue #3: No Unique Constraints
The track_the_click_link table has no unique constraint on (post_id, url, page_url), which could allow duplicates and cause query ambiguity.
PHP Version Connection:
Unclear. The bug appears to be in the code logic rather than PHP version-specific, though PHP 8.0+ may surface errors that were previously silent.
You must be logged in to reply to this topic.