Tag Archives: Drupal Schema API

Drupal 7 – Update the module schema by hook_update_N()

Recently i start working on BeansTag again as some users request to add the meta robots and canonical options.

This time, the update involves a change in the module schema. In this case, we need to implement the hook_update_N() in .install.

The following piece of code is added to beanstag.install. Continue reading Drupal 7 – Update the module schema by hook_update_N()

Advertisements

Drupal 7 – Get the number of results in db_select()

We can get the number of returned rows in db_select() by ->rowCount().

// Get the number of nodes created by administrator
$query = db_select('node', 'n');
$result = $query->fields('n', array('nid'))->condition('uid', 1, '=')->execute();
return $result->rowCount();

 

Done =)

Reference: Drupal forum – get count with db_select

Drupal 7 – Create a Datetime field in hook_schema() @ 2

Yesterday we talked about defining a datetime field for the table created by custom module.
Drupal 7 – Create a Datetime field in hook_schema() @ 1

As i have mentioned in the above post, the datetime field is no longer support by the Drupal Schema API. If you don’t want to use the datetime field, you can try to save the datetime in timestamp format and stored it in an int column.
Continue reading Drupal 7 – Create a Datetime field in hook_schema() @ 2

Drupal 7 – Create a Datetime field in hook_schema() @ 1

Next: Drupal 7 – Create a Datetime field in hook_schema() @ 1

If your custom module requires an additional table in the Drupal database, you have to create the .install file and define the schema inside it. In Drupal 7, the datetime field is no longer support by the Drupal Schema API. If you want to create a datetime field, you have to use the mysql_type or pgsql_type. Here is an example.
Continue reading Drupal 7 – Create a Datetime field in hook_schema() @ 1