Я создал приложение для запуска на стороне клиента (JavaScript и HTML), которому требуется доступ и обновление данных на сервере. Имеет схему, которая состоит из 5 таблиц. Я точно определил, как они должны выглядеть в JSON. Я хочу, чтобы они были доступны как сервис JSON, обслуживаемый из модуля Drupal. Я понимаю, как использовать drupal_json_output для предоставления результатов. Я просто не могу найти простой способ убедиться, что для них создана таблица базы данных, а затем добавлять и удалять элементы из нее. Я хотел бы сохранить независимость Drupal от основной базы данных. Мне не нужны никакие функции поиска, функции форм и т. Д. Я просто хочу использовать абстракцию базы данных Drupal.
На данный момент я попробовал следующее в моем установочном файле:
/**
* Implements hook_schema
*/
function rcsarooms_schema(){
$schema = array();
$schema['rcsarooms'] = array(
'description' => 'Stores the structured information about the rooms and staircases.',
'fields' => array(
'ID' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'description' => 'Primary Key: used in the URLs to identify the entity.'
),'Name' => array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
'description' => 'The name used for links in the navigation menues.'
),'ParentID' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'description' => 'The ID of the parent element or "Root" if this is a root element'
),'Type' => array(
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'description' => 'page, staircase, house, room or special'
),'BathroomSharing' => array(
'type' => 'int',
'description' => 'The number of people the bathroom is shared with (0 for unknown)'
),'RentBand' => array(
'type' => 'int',
'description' => 'The ID of the rent band the room is in.'
),'Floor' => array(
'type' => 'int',
'description' => 'The floor number (0 is courtyard level).'
)
),
'primary key' => array('ID')
);
return $schema;
}
И следующее в моем файле модуля:
/**
* Implements hook_menu
*/
function rcsarooms_menu(){
$items['rcsarooms'] = array(
'page callback' => 'rcsarooms_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
}
function rcsarooms_callback(){
drupal_json_output(db_query("SELECT * FROM {rcsarooms}"));
drupal_exit();
return;
}
Это дает следующую ошибку, когда я пытаюсь перейти к rcsarooms:
PDOException: SQLSTATE [42S02]: Базовая таблица или представление не найдено: 1146 Таблица 'db.rcsarooms' не существует: SELECT * FROM {rcsarooms}; Array () в rcsarooms_callback ()