1

Is it necessary to connect to drupal database in order to fetch something from database? OR no if I have drupal installed so no need to make connection in any template file in order to fetch data?

1

3 Answers 3

0

The database connection is handled elsewhere, you do not need to write a new connection function in your template file.

You can use this:
https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_query/7

0

The easy answer is yes...Drupal uses a entity value attribute (EVA) data model which makes pulling tabular data directly from a MySQL client challenging at best.

You would be better off installing the feeds or Views data export module(s) to retreive the data you want and export as a CSV.

0

| I have drupal installed so no need to make connection in any template file in order to fetch data?

You should not be fetching data in template files, I highly recommend you instead create a small custom module and use either a theme_hook or preprocess functions to push data in your templates. You really want to avoid having "logic" in templates.

You can query the DB with db_query or any other Database api function in your custom module's code.

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.