Есть запрос на php к базе mysql
/* Соединяемся, выбираем базу данных */
mysql_connect("localhost", "11111", "11111")
or die("Could not connect");
mysql_select_db("11111_db") or die("Could not select database");
/* Выполняем SQL-запрос */
$q = "SELECT * FROM `Dep`";
$result = mysql_query($q) or die("Query failed");
/* Выводим результаты в html */
print "
$col_value |
\n";
/* Освобождаем память от результата */
mysql_free_result($result);
/* Закрываем соединение */
mysql_close($link);
?>
Информацию выводит, но не отображает тему друпала и выводит кучу ошибок!
Вот ошибки:
* warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /var/www/virtual/drupal/htdocs/includes/common.inc(1641) : eval()'d code on line 27.
* user warning: Table 'department_db.system' doesn't exist query: SELECT * FROM system WHERE type = 'theme' in /var/www/virtual/drupal/htdocs/includes/theme.inc on line 449.
* user warning: Table 'department_db.cache' doesn't exist query: SELECT data, created, headers, expire, serialized FROM cache WHERE cid = 'theme_registry:' in /var/www/virtual/drupal/htdocs/includes/cache.inc on line 26.
* user warning: Table 'department_db.cache' doesn't exist query: UPDATE cache SET data = 'a:146:{s:24:\"block_admin_display_form\";a:7:{s:8:\"template\";s:38:\"modules/block/block-admin-display-form\";s:4:\"file\";s:29:\"modules/block/block.admin.inc\";s:9:\"arguments\";a:1:{s:4:\"form\";N;}s:4:\"type\";s:6:\"module\";s:10:\"theme path\";s:13:\"modules/block\";s:11:\"theme paths\";a:1:{i:0;s:13:\"modules/block\";}s:20:\"preprocess functions\";a:2:{i:0;s:19:\"template_preprocess\";i:1;s:44:\"template_preprocess_block_admin_display_form\";}}s:17:\"color_scheme_form\";a:6:{s:9:\"arguments\";a:1:{s:4:\"form\";N;}s:4:\"type\";s:6:\"module\";s:10:\"theme path\";s:13:\"modules/color\";s:8:\"function\";s:23:\"theme_color_scheme_form\";s:11:\"theme paths\";a in /var/www/virtual/drupal/htdocs/includes/cache.inc on line 109.
* user warning: Table 'department_db.locales_source' doesn't exist query: SELECT s.lid, t.translation, s.version FROM locales_source s LEFT JOIN locales_target t ON s.lid = t.lid AND t.language = 'ru' WHERE s.source = 'Thu' AND s.textgroup = 'default' in /var/www/virtual/drupal/htdocs/modules/locale/locale.module on line 376.
* user warning: Table 'department_db.locales_source' doesn't exist query: INSERT INTO locales_source (location, source, textgroup, version) VALUES ('/node/10', 'Thu', 'default', '6.8') in /var/www/virtual/drupal/htdocs/modules/locale/locale.module on line 392.
* user warning: Table 'department_db.cache' doesn't exist query: DELETE FROM cache WHERE cid LIKE 'locale:%' in /var/www/virtual/drupal/htdocs/includes/cache.inc on line 175.
* user warning: Table 'department_db.system' doesn't exist query: SELECT * FROM system WHERE type = 'theme' in /var/www/virtual/drupal/htdocs/includes/theme.inc on line 449.
* user warning: Table 'department_db.node_revisions' doesn't exist query: SELECT pv.value AS last_editor, u.uid AS the_uid FROM node_revisions nr, users u, profile_values pv WHERE nr.uid = u.uid AND pv.fid = 1 AND nr.uid = pv.uid AND nr.nid = 10 ORDER BY timestamp DESC LIMIT 1 in /var/www/virtual/drupal/htdocs/modules/node/node.tpl.php on line 86.
* user warning: Table 'department_db.node_revisions' doesn't exist query: SELECT u.name AS last_editor, u.uid AS the_uid FROM node_revisions nr, users u WHERE nr.uid = u.uid AND nr.nid = 10 ORDER BY timestamp DESC LIMIT 1 in /var/www/virtual/drupal/htdocs/modules/node/node.tpl.php on line 100.
* user warning: Table 'department_db.history' doesn't exist query: SELECT timestamp FROM history WHERE uid = 1 AND nid = 10 in /var/www/virtual/drupal/htdocs/modules/node/node.module on line 179.
* user warning: Table 'department_db.system' doesn't exist query: SELECT info FROM system WHERE type = 'theme' AND name = 'salamander1' in /var/www/virtual/drupal/htdocs/modules/system/system.module on line 974.
* warning: array_map(): Argument #2 should be an array in /var/www/virtual/drupal/htdocs/modules/system/system.module on line 975.
* warning: array_keys(): The first argument should be an array in /var/www/virtual/drupal/htdocs/includes/theme.inc on line 1760.
* warning: Invalid argument supplied for foreach() in /var/www/virtual/drupal/htdocs/includes/theme.inc on line 1760.
* user warning: Table 'department_db.cache_menu' doesn't exist query: SELECT data, created, headers, expire, serialized FROM cache_menu WHERE cid = 'links:navigation:page-cid:node/10:1' in /var/www/virtual/drupal/htdocs/includes/cache.inc on line 26.
* user warning: Table 'department_db.menu_links' doesn't exist query: SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM menu_links WHERE menu_name = 'navigation' AND link_path IN ('node/10') in /var/www/virtual/drupal/htdocs/includes/menu.inc on line 890.
* user warning: Table 'department_db.menu_links' doesn't exist query: SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM menu_links WHERE menu_name = 'navigation' AND link_path = 'node/%' in /var/www/virtual/drupal/htdocs/includes/menu.inc on line 895.
* user warning: Table 'department_db.menu_links' doesn't exist query: SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.* FROM menu_links ml LEFT JOIN menu_router m ON m.path = ml.router_path WHERE ml.menu_name = 'navigation' AND ml.plid IN (0) ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC in /var/www/virtual/drupal/htdocs/includes/menu.inc on line 933.
* user warning: Table 'department_db.cache_menu' doesn't exist query: SELECT data, created, headers, expire, serialized FROM cache_menu WHERE cid = 'links:navigation:tree-data:5d6d3aaaaef5fba302ce62698fa37bbe' in /var/www/virtual/drupal/htdocs/includes/cache.inc on line 26.
* user warning: Table 'department_db.cache_menu' doesn't exist query: UPDATE cache_menu SET data = 'a:2:{s:4:\"tree\";a:0:{}s:10:\"node_links\";a:0:{}}', created = 1238052263, expire = 0, headers = '', serialized = 1 WHERE cid = 'links:navigation:tree-data:5d6d3aaaaef5fba302ce62698fa37bbe' in /var/www/virtual/drupal/htdocs/includes/cache.inc on line 109.
* user warning: Table 'department_db.cache_menu' doesn't exist query: UPDATE cache_menu SET data = 'links:navigation:tree-data:5d6d3aaaaef5fba302ce62698fa37bbe', created = 1238052263, expire = 0, headers = '', serialized = 0 WHERE cid = 'links:navigation:page-cid:node/10:1' in /var/www/virtual/drupal/htdocs/includes/cache.inc on line 109.
* user warning: Table 'department_db.menu_router' doesn't exist query: SELECT * FROM menu_router WHERE tab_root = 'node/%' ORDER BY weight, title in /var/www/virtual/drupal/htdocs/includes/menu.inc on line 1306.
Комментарии
Ну даже и незнаю.
Ну попробуйте убрать mysql_close($link) темболее что никакой $link не существует
А вообще глядя на скрипт я не понимаю с чего бы это тема друпала загружалась.
1. Прописываем параметры подключения к альтернативной БД в settings.php
<?php
$db_url['default'] = 'mysql://test:test@mysql/test_acquia2';
$db_url['wagora'] = 'mysql://test:test@mysql/test_agoacquia';
$db_prefix = '';
?>
2. В вашем коде:
<?php
db_set_active('wagora');
//набор запросов к альтернативной БД? пользовать функции drupal
//db_query(), db_result() и т.д.
db_set_active('default');
//обработка извлеченных из БД данных.
?>
Если вам необходимо на друпал-сайте использовать данные из другой базы (может быть даже с другого хоста), то это достаточно просто сделать.
читайте здесь
Спасибо, заработало все четко. Только в settings.php прописал так
<?php
$db_url = array(
'default'=>'mysql://username:pass@localhost/databasename',
'Data_db'=>'mysql://username1:pass@host1/databasename1'
);
?>