Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin Tips & Tricks
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
How can I use a external database with vb Blocks
xman_79's Avatar
xman_79
Join Date: Jun 2006
Posts: 65

 

Romania
Show Printable Version Email this Page Subscription
xman_79 xman_79 is offline 03-14-2010, 10:00 PM

Hi , Sorry because my English is weak, but I liked to write a topic on the use of an external database within the Forum's Blocks .

Go to : admincp -> Forums & Moderators -> Forum Blocks Manager -> Add Block : Custom Html / Php

Add new block: Custom HTML/PHP
Title : Your title ;
Description : your description ;
Cache Time (in minutes) : 60;
Content Type : Php
Content : ***
Template to Use : add your template . (eg. block_html)

The content :

PHP Code:

//THIS IS NOT THE DATABASE OF VBULLETIN
DEFINE ('DB_USER''CHANGE_TO_USER');
DEFINE ('DB_PASSWORD''CHANGE_TO_PASSWORD');
DEFINE ('DB_HOST''CHANGE_TO_HOST'); 
DEFINE ('DB_NAME''CHANGE_TO_DB_NAME');

if(
$dbc mysql_connect(DB_HOSTDB_USERDB_PASSWORD))
{
    if(!
mysql_select_db(DB_NAME))
    {
        return 
false;
    }
}
else
{
    return 
false;
}

ob_start();

$testquery     mysql_query("SELECT * from NAME_OF_TABLE");
$testarray     = array();
while(
$testrow mysql_fetch_array($testquery))
{
    
$testarray["$testrow[SOMEID]"] = $testrow;
}
unset(
$testrow);
mysql_free_result($testquery);

$templater vB_Template::create('YOUR_TEMPLATE_NAME');
    
$templater->register('mytestvar'$testarray);
$output .= $templater->render();

$output .= ob_get_contents();

return 
$output;

ob_end_clean(); 
The template (YOUR_TEMPLATE_NAME) .
Create a new template .

HTML Code:
<ul>
<vb:each from="mytestvar" key="SOMEID" value="testrow">
<li>{vb:raw testrow.somerow}</li>
</vb:each>
</ul>
Eg.

Attachment 114191
Reply With Quote
  #2  
Old 03-20-2010, 10:53 AM
ChopSuey ChopSuey is offline
 
Join Date: Jun 2009
Location: Alaska
Posts: 2,140
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

& What is in your db? For the screenshot? Looks like a normal forum block.
Reply With Quote
  #3  
Old 03-20-2010, 04:00 PM
mandingo's Avatar
mandingo mandingo is offline
 
Join Date: Jun 2008
Posts: 307
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

He's just showing how to call content from a different database other than your forum one.
Reply With Quote
  #4  
Old 06-17-2010, 02:53 PM
xman_79's Avatar
xman_79 xman_79 is offline
 
Join Date: Jun 2006
Location: Romania
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ChopSuey View Post
& What is in your db? For the screenshot? Looks like a normal forum block.
Yes, it is a normal forum block but the content is not from vb-db.
In my another db i have an article system, so I display the list of sections .
Reply With Quote
  #5  
Old 06-17-2010, 03:08 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Couple of suggestions...

When going outside the vB DB class, track your new connection by explicitly using the resource identifiers Like...

PHP Code:
mysql_select_db(DB_NAME,$dbc)
mysql_query("SELECT * from NAME_OF_TABLE"$dbc
After your mysql_free_result you might want to add mysql_close($dbc).

Try putting your ob_end_clean() before your return $output too. Although, I don't see the point of using it. I guess you're trying to catch any errors and tag them on to the output?

I'm not crazy about using constants (DEFINE) for passwords and such either.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:35 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.04518 seconds
  • Memory Usage 2,266KB
  • Queries Executed 21 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_html
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (4)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete