Since drupal is our preferred content management system, we will draw your attention to the Pro Drupal book more precisely Pro Drupal Development chapter 5 Working With databases. In a sense drupal has its own database language that is database agnostic building on the PHP PDO object: http://php.net/manual/en/book.pdo.php That means that you perform queries with the statement db_query(), instead of mysql_query() or pg_query(). The statements are prepared: http://www.php.net/manual/en/pdo.prepar ... ements.php to avoid sql injection attacks.
2. Bootstrap drupal so you can issue queries.
If you look in the bootstrap.inc file in the includes directory of your drupal installation, you find the following information:
Code: Select all
* Ensures Drupal is bootstrapped to the specified phase.
* In order to bootstrap Drupal from another PHP script, you can use this code:
* define('DRUPAL_ROOT', '/path/to/drupal');
* require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
* @param $phase
* A constant telling which phase to bootstrap to. When you bootstrap to a
* particular phase, all earlier phases are run automatically. Possible
* - DRUPAL_BOOTSTRAP_CONFIGURATION: Initializes configuration.
* - DRUPAL_BOOTSTRAP_PAGE_CACHE: Tries to serve a cached page.
* - DRUPAL_BOOTSTRAP_DATABASE: Initializes the database layer.
* - DRUPAL_BOOTSTRAP_VARIABLES: Initializes the variable system.
* - DRUPAL_BOOTSTRAP_SESSION: Initializes session handling.
* - DRUPAL_BOOTSTRAP_PAGE_HEADER: Sets up the page header.
* - DRUPAL_BOOTSTRAP_LANGUAGE: Finds out the language of the page.
* - DRUPAL_BOOTSTRAP_FULL: Fully loads Drupal. Validates and fixes input
* @param $new_phase
* A boolean, set to FALSE if calling drupal_bootstrap from inside a
* function called from drupal_bootstrap (recursion).
* The most recently completed phase.
3. How to bootstrap drupal in the home directory of an add on domain.
Since drupal is installed in the home directory of my addon domain, I use the following code:
Code: Select all
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
4. Running queries against the database.
Now it is possible to run queries using db_query() as explained in chapter 5 of the book mentioned in the introduction.
5. Additional information and examples.
http://api.drupal.org/api/drupal/core%2 ... database/8