Connect to an external db

Sometimes it is useful to use another database than the one installed by default by Drupal.
1. Declare the database in settings.php
the entry default / default is created by Drupal (no idea why it is 2 times default...)

  1. $databases = array (
  2. 'default' =>
  3. 'default' =>
  4. 'database' => 'drupal_db',
  5. 'username' => 'xxx',
  6. ...
  7. ),
  8. ),
  9. 'myotherdb' =>
  10. 'default' =>
  11. 'database' => 'my_snippet',
  12. 'username' => 'xxx',
  13. ...
  14. ),
  15. ),
  16. );

2.then in a module use db_set_active() function to switch from database.

  1. db_set_active('myotherdb');
  2. db_query("select snippet_nid from xx");

Form field conditionnal display

In this snippet the text field mycustom is only displayed if the value of the select field myoptions is custom

Theme and render

display some content using drupal_render() and theme (this is the official way to use theme function)

Simple block definition

Define and set content into a block. See hook_block_configure and hook_block_save if you want people be able to choose options.

Form declaration (from menu to submit)

Output a simple form, with validation and submit handlers

Jquery file structure declaration

Declare custom jquery code (attached to a theme or module) so that $ selector is available