Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Two main issues here:
1) This function ignores $limit. It shouldnt
2) Shouldnt "$rows = $node_title_query->execute()->fetchAll(PDO::FETCH_ASSOC);" use fetchallassoc instead?