I am using Views PHP module for custom coding in views.

I tried using mysql_connect function to connect to a remote database using the "GLOBAL PHP" field and get some data through custom coding. Is it safe to connect to database through the "GLOBAL PHP" field? Or are there any security risks?

1 Answer 1


Nothing is a security risk in and of itself. If you know basic PHP and the basic usage of mysql_query and how to sanitize your input -- you're fine.

What you're proposing is not by any means a best practice, proper use of Views or the Drupal API (sorry).

All of these options make use of Drupal core features for interacting with 3rd party databases, Drupal API or Views contributed module API.

Your approach is taking an embedded php field in a view and ignoring Drupal and its architecture to achieve what you want. It's as secure and safe as your experience and knowledge make it. I prefer to stand on the shoulders of others and leverage the security built into Drupal and its supported APIs.

You may find the Data module useful in making your 3rd party data play nicer with Views.

Data module helps you model, manage and query related sets of tables. It offers an administration interface and a low level API for manipulating tables and accessing their contents. Data module provides Views integration for displaying table data and Drupal search integration for searching table content.

  • Thanks. I know there are other ways but I am not good at Drupal Programming. I could easily manage all through PHP using "Views PHP". Thanks for the detail.
    – bPadaria
    Mar 12, 2014 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.