Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module of the week Webform 7.x-4.0-alpha9 – admin/config/content/webform Add content types, choose allowed fields, default values and advanced options.

Similar presentations


Presentation on theme: "Module of the week Webform 7.x-4.0-alpha9 – admin/config/content/webform Add content types, choose allowed fields, default values and advanced options."— Presentation transcript:

1 Module of the week Webform 7.x-4.0-alpha9 – admin/config/content/webform Add content types, choose allowed fields, default values and advanced options – Create node as normal – Click webform – Add fields as needed to form. – Add conditionals and validation after fields

2 Accessing External Databases Outline settings.php db_set_active Queries – db_query – db_select Accessing Results – foreach – ->fetchAssoc()

3 settings.php Manual – Use your favorite text editor – File found in sites/sitename/settings.php – Sample in sites/default/settings.php – Each entry is an array in the array $databases – Main database is $databases[‘default’][‘default’]=array(…

4 settings.php Manual (continued) – Other databases are generally $databases[‘handle’][‘default’]=array(… – Slave databases are $databases[‘handle’][‘slave’][]=array(… – Prefix arrays are mainly used for multiple sites sharing a database.

5 settings.php Manual (continued) – Required Fields ‘driver’ => ‘mysql’ | ‘pgsql ‘| ‘sqlite’ – Normal Fields (for mySQL, pgSQL, MariaDB) ‘username’ = ‘Username’, ‘password’ => ‘Password’, ‘host’ => ‘hostname of server’ | ‘localhost’, ‘database’ => ‘name in server’, ‘port’ => ‘portnumber’, (often 3306)

6 settings.php Manual (continued) – Normal Fields (for sqlite) ‘database’ => ‘path on local server’, – Optional Fields ‘prefix’ => array( ‘default’ => ‘prefix1’, ‘tablename1’ => ‘prefix2’, ‘tablename2’ => ‘prefix3’, … ), ‘prefix’ => ‘prefix’,

7 settings.php AED – Attach External Databases drupal.org/sandbox/kwfinken/2022339 Install as normal Adding a database to settings.php – Configuration|Development|aed: – Type in database connection info. – Click [Save Settings and Add this Database] – Click on the name of the Database – Click [Add to settings.php]

8 AED Remove a Database from settings.php (only works if installed by AED) – Click the name of the database – Click [Remove from settings.php] Edit Database connection info – Remove from settings.php as above – Click the name – Make the changes – Click Update – Add to settings.php as above

9 db_set_active Tells drupal which database to access Syntax: db_set_active(‘database_handle’); /* database related code */ db_set_active(); Always minimize the code between setting the database and returning to default. Normal Drupal functions won’t work between these.

10 Queries Between db_set_active()s db_query($query,$args,$options) – $query = ‘some sql query’ $result = db_query($query); – optional arguments $args() – array of parameters to substitute into query Use a named array of format ‘:name’=>value, to substitue for :name in query $options() – list of options to control how the query executes

11 Queries Between db_set_active()s db_select($table,$alias,$options) – Use a string of methods to add details: ->fields(‘alias’,[array(‘fields’, …)]) ->condition(‘field’, comparison, ‘operator’) – Comparison is a value or an array of values ->join(‘table2’, ‘alias’, ‘join’) ->groupBy(‘alias.field’) etc. ->execute()

12 Queries Between db_set_active()s db_select($table,$alias,$options) – Example: $result = Db_select(‘hours’,’h’)->fields(‘h’,array(‘date’, ‘open_time’, ‘close_time’)) ->condition(‘h.date’, $today, ‘>=’) ->groupBy(‘h.date’) ->execute();

13 Accessing Results Comes after db_set_active() foreach – foreach($result as $row){ $row->fieldname; } $row=$result->fetchObject() – $row->fieldname;

14 Accessing Results Comes after db_set_active() $row=$result->fetchAssoc() – $row[‘fieldname’]; – foreach($row as $field=>$value){ $value; $field; } – foreach($row as $value){ $value; }

15 Where does this code go? Custom Module – Preferred Method A text area configured to “PHP code” filter. – This is generally considered unsafe! References: – http://it-ebooks.info/go.php?id=1472-1375228464- 40c7d5f0648261b73c47a56a08287c88 better for DB functions. http://it-ebooks.info/go.php?id=1472-1375228464- 40c7d5f0648261b73c47a56a08287c88 – http://it-ebooks.info/go.php?id=1455-1375227046- aeb771ecac544950271ffa536b233caf better for Module Development http://it-ebooks.info/go.php?id=1455-1375227046- aeb771ecac544950271ffa536b233caf


Download ppt "Module of the week Webform 7.x-4.0-alpha9 – admin/config/content/webform Add content types, choose allowed fields, default values and advanced options."

Similar presentations


Ads by Google