Thursday, August 8, 2013

Drupal PDO error : Invalid input syntax for integer

Error:

        PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer:

Reason:

Drupal will not recognize the node URL when the node id is not an integer. This will happens when URL like node/abc instead of node/12. It fails to get the desired node URL location from the database. It's bug of Drupal Core.

Solution:

To filter out the non numeric node id's from the URL from executing use the below patch in Drupal core file called includes/entity.inc. Add the lines as first in function called load().

    public function load($ids = array(), $conditions = array()) {
        //Add the below code patch

        //-----Patch Start----

        if (is_array($ids)) {
        // Removes all non numeric ids.
        $ids = array_filter($ids, function($x){
                return preg_match('/^[0-9]+$/', $x);
                });
        }

        //-----Patch End----
        $entities = array();


No comments:

Post a Comment