vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Cross Database Queries (https://vborg.vbsupport.ru/showthread.php?t=133241)

theferf 12-04-2006 11:16 PM

Cross Database Queries
 
I am in the process of developing a plugin to access data from a DB outside of vBulletin's database, yet still on the same mySQL server. Normally, this can be done in mySQL by formatting the query as follows:
Code:

SELECT table1.foo FROM db1.table1 WHERE table1.foo='bar';
Where db1 is the name of the external database (on the same DB server). When I attmept this in my plugin I end up with:
Code:

Database error in vBulletin 3.6.2:

Invalid SQL:
SELECT table1.foo FROM db1.table1 where table1.foo='bar';

MySQL Error  : Table 'db1.table1' doesn't exist
Error Number : 1146

Of course, I've renamed the DB and table in this example to protect the innocent. ;) The DB and the table do exist, but for some reason the $db->query() usage in VB won't let me do this. I have used the very same method in PHP's native mysql_query() many, many times. Is there something in the VB database class that prevents this?

CyberAlien 12-05-2006 11:33 AM

Maybe database user set in vbulletin config is not allowed to access db1?

theferf 12-05-2006 03:26 PM

Thanks for the reply CyberAlien. I found my issue. For some reason vB threw the error in my example because I didn't also use the identifier for the SELECT. It's now working as:
Code:

SELECT db1.table1.foo FROM db1.table1 WHERE db1.table1.foo='bar';
I'm not sure if that's being overly strict, but it's a good coding habit anyway IMHO.


All times are GMT. The time now is 01:03 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01034 seconds
  • Memory Usage 1,710KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete