insert data into database using web service I am creating a custom web service. In this, as soon as service call, data should be store into database. I am using Hook_service_resource() function. How can i implement insertion into database using services. I created my_module.install file and prepare database schema. BUT i actually don't know how to use query in hook_service_resource() function.
Create a Custom Drupal Module


Create these empty files in the new directory:


my_module.info
my_module.module
my_module.install
my_module.resource.inc
my_module.services.inc



Place this code in the my_module.info file:

name = My Module
description = My custom Drupal module.
package = Other
core = 7.x
dependencies[] = services
dependencies[] = rest_server


Place this code in the my_module.module file:

&lt;?php

/**
 * Implements hook_ctools_plugin_api().
 */
function my_module_ctools_plugin_api($owner, $api) {
  if ($owner == 'services' &amp;&amp; $api == 'services') {
    return array(
      'version' =&gt; 3,
      'file' =&gt; 'my_module.services.inc'
    );
  }
}


Place this code in the my_module.services.inc file:

&lt;?php

function my_module_services_resources() {
  $resources = array(
    'my_module_resources' =&gt; array(
      'actions' =&gt; array(
        'insert_into_database' =&gt; array(
          'help' =&gt; t('Insert Database Example.'),
          'file' =&gt; array(
            'type' =&gt; 'inc',
            'module' =&gt; 'my_module',
            'name' =&gt; 'my_module.resource',
          ),
          'callback' =&gt; 'my_module_insert_into_db',
          'args' =&gt; array(),
          'access arguments' =&gt; array('access user profiles'),
          'access arguments append' =&gt; FALSE,
        ),
      ),
    ),
  );
  return $resources;
}


Place this code in the my_module.resource.inc file:

&lt;?php

function my_module_insert_into_db() {
  $id = db_insert('example_table') // Table name no longer needs {}
-&gt;fields(array(
  'title' =&gt; 'Example',
  'uid' =&gt; 1,
))
-&gt;execute();
  if ($id) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}


Change the access arguments as per your permissions settings..

Call the service

http://www.example.com/?q=serviceendpoint/my_module_resources/insert_into_database.json