vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin Tips & Tricks (https://vborg.vbsupport.ru/forumdisplay.php?f=239)
-   -   How can I use a external database with vb Blocks (https://vborg.vbsupport.ru/showthread.php?t=238334)

xman_79 03-14-2010 10:00 PM

How can I use a external database with vb Blocks
 
1 Attachment(s)
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

ChopSuey 03-20-2010 10:53 AM

& What is in your db? For the screenshot? Looks like a normal forum block.

mandingo 03-20-2010 04:00 PM

He's just showing how to call content from a different database other than your forum one.

xman_79 06-17-2010 02:53 PM

Quote:

Originally Posted by ChopSuey (Post 2006991)
& 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 .

noppid 06-17-2010 03:08 PM

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.


All times are GMT. The time now is 02:01 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.01111 seconds
  • Memory Usage 1,734KB
  • 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
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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