Insecure code

Nerver trust EXPLAIN unless you run a large Drupal site

Last modified: August 28, 2009 - 12:58

Of course, you can believe in EXPLAIN to guide you very well, as explained earlier.

Here trust means absolute confidence.
Can you trust EXPLAIN to display the right query plan and the real execution time?

The answer is probably YES and NO.

EXPLAIN and EXPLAIN ANALYSE allows you to display a query plan.

This information is based on algorithms and run-time statistics.

Whener you run a site in production, the planner will benchmark SQL execution times log.
After a few days of running your web site live, the planner might find and apply optimizations.

A modern database is always learning from its mistakes.
This is why planners are the most difficult piece of software to write.

Here are the following consequences:

  • Learning phase
    When developing a new module for Drupal or when testing a fresh installation, the planner does not have enough statistics to find the right query plan and execute the query fast. Therefore, you may find that some query is executing slowly. In fact, the planner may be in a learning phase. But be aware this may change when going live.
  • Comparision
    Also, be warned that during discussions on a mailing list, you may compare query plan results on different databases, one being a development database and the other a live system.

    Developer A will say : "This executes in 100ms"

How to add more Flash players to the Audio module

Last modified: May 21, 2009 - 06:32

This guide is for the audio-6.x-1.0-unstable4 version of the Audio module. It will probably work for other versions, but has not been tested, so use at your own risk.

This guide covers how to incorporate other Flash Audio players into the Audio module.

Server Info

Last modified: March 15, 2009 - 02:23

<?php
phpinfo
();
?>

Drupal Doodle Like Content Type sample

Last modified: January 15, 2009 - 18:29

Searching for a module with features like doodle, i build one using cck and a custom node.tpl ...
Maybe this can be usefull for someone.
It will allow the authentificated user to vote on multiple date options.

Doodle like content type

We add a news content type. I call it fix_a_date.
This content type has a title and body and a cck field type 'date'.
Widget: Date: Text Field with jquery pop-up calendar if installed
Label: date_choice

On data settings we allow unlimited multiple dates.
Choose your Granularity, i think you do not need Seconds.
On Time Zone choose User's time zone.

Now we can create a content type where the users can put multiple dates
fields used later as choices.

Create one ...

Drupal choice storage table

Now we need the database table for storing the users choices ..
!! hardcoded in the functions below ..


CREATE TABLE IF NOT EXISTS `fix_a_date` (
`nid` int(11) unsigned NOT NULL,
`uname` varchar(255) collate utf8_unicode_ci NOT NULL,
`submitted` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`remote_addr` varchar(50) collate utf8_unicode_ci NOT NULL,
`fieldname` varchar(80) collate utf8_unicode_ci NOT NULL,
`value` varchar(255) collate utf8_unicode_ci NOT NULL,
`data` varchar(255) collate utf8_unicode_ci NOT NULL,
`uid` int(11) unsigned NOT NULL,

Advanced and multisite installation

Last modified: October 15, 2009 - 02:31

The following pages cover some special installation cases, such as running several Drupal sites from a single code base (also known as multi-site installations) and specifying a database table prefix.

Simple form to email example

Last modified: March 14, 2009 - 23:10

Inspired by http://drupal.org/node/197092 I decided to write a short snippet to demo how to take a simple form field, validate it and send the field to an email address on submission.

Like the above post, this snippet just asks for an email address with a submit button. Validation just checks the email address syntax.

This is really meant as a "starting point", it's up to you, the reader, to add bells and whistles as required.

To use this snippet, create a new block. Cut'n'paste the code below and set the blocks input filter to "PHP". Then place the block somewhere to use it.

<?php

$send_form_to = 'jdow@example.com'; // Change this!

function my_sign_up_form() {
$form['email'] = array(
'#type' => 'textfield',
'#title' => '',
'#size' => '20',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Subscribe',
);
return $form;
}

function my_sign_up_form_validate($form_id, $form) {
if (!valid_email_address($form['email'])) {
form_set_error('email', 'Your email address appears malformed');
}
}

function my_sign_up_form_submit($form_id, $form) {
$message = 'New signup email address: '. $form['email']; // Body of your email here.
drupal_mail('my_sign_up_form', $send_form_to, 'New signup', $message, variable_get('site_mail', 'an@example.com'));

Syndicate content
 
 

Drupal is a registered trademark of Dries Buytaert.