View Full Version : query_first_slave() error when trying to use vBulletin API outside of vBulletin
nvitremi
08-06-2008, 02:22 PM
Hi,
Since the past two days, the only thing I'm trying to do with vBulletin is to display a login form or a user information box (when the user is logged in) on every pages of the site, including those not in vBulletin. That's it -- nothing fancy. I do not need or want full integration capabilities -- just display a user information box or a login box whether the user is logged in or not.
I followed a tutorial I found on this site (https://vborg.vbsupport.ru/showthread.php?t=98009) and tried to make a page outside of vBulletin's directory and still use vBulletin's API. Even though I followed the instructions to the letter, I can't make a page outside vBulletin. I get the following error message:
Call to a member function query_first_slave() on a non-object in /var/nvisionit/projects/precisionnutrition/www-newcms/forum/includes/functions.php on line 1303
Is there anything I can do to make this thing work once and for all?
Any help will be appreciated. Thanks in advance!
Lynne
08-06-2008, 02:46 PM
You should post the code so people can see it.
nvitremi
08-06-2008, 03:01 PM
Here it is:
<?php
// https://vborg.vbsupport.ru/showthread.php?t=98009
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// ##################### DEFINE IMPORTANT CONSTANTS #######################
// change the line below to the actual filename without ".php" extention.
// the reason for using actual filename without extention as a value of this constant is to ensure uniqueness of the value throughout every PHP file of any given vBulletin installation.
define('THIS_SCRIPT', 'test');
// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array(
// change the lines below to the list of actual templates used in the script
'pn_test',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ########################## REQUIRE BACK-END ############################
$forumdir = $pnsite->getConfig('forumdir');
chdir($forumdir);
require_once('./global.php');
// I checked the "forumdir" above and the path is correct
// since the file "global.php" gets loaded.
// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude = str_replace('clientscript', $vbulletin->options['bburl'] . '/clientscript', $headinclude);
// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################
$navbits = array();
// change the line below to contain whatever you want to show in the navbar (title of your custom page)
$navbits[$parent] = 'Test Page';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
print_output($navbar);
// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' . fetch_template('pn_test') . '");');
I also cleared all my cookies for the site, thus I'm no longer logged in. I get different errors in this case:
Warning: array_keys() [function.array-keys]: The first argument should be an array in [path]/includes/functions.php on line 4088
Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 4088
( ! ) Fatal error: Call to a member function query_read_slave() on a non-object in /var/nvisionit/projects/precisionnutrition/www-newcms/forum/includes/functions.php on line 3093
Lynne
08-06-2008, 03:22 PM
What are you spitting out though? I see you eval your template pn_test, but nothing is there to go into pn_test - perhaps post that template. Also, I hope you have a closing php tag at the end ("?>")? And, I don't think you need the line "print_output($navbar);"
nvitremi
08-06-2008, 03:58 PM
I usually don't put closing tags when I only have PHP code in my file. See "Instruction separation (http://ca.php.net/basic-syntax.instruction-separation)" in PHP documentation.
Execution errs at "global.php". Anything after that is not executed.
--------------- Added 1218043772 at 1218043772 ---------------
I forgot to mention the custom template "pn_test" simply contains "TEST".
Lynne
08-06-2008, 04:38 PM
Does it work if you do the following:
// ########################## REQUIRE BACK-END ############################
chdir(/path/to/the/vbulltin/forums);
require_once('./global.php');
nvitremi
08-06-2008, 04:43 PM
No. Still the same happens -- no different.
Paul M
08-06-2008, 06:45 PM
What version of VB are you running ?
Lynne
08-06-2008, 06:45 PM
Um, I just noticed something.... you didn't really create a template that only has the word "TEST" in it, did you? It needs to be html compliant. ie:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header
$navbar
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat" colspan="2">Title</td>
</tr>
<tr>
<td class="alt1" colspan="2">Text</td>
</tr>
</table>
$footer
</body>
</html>
Also, as I said, be sure to remove the print_output line.
Marco van Herwaarden
08-07-2008, 08:10 AM
I really don't see how the following can work:
// ########################## REQUIRE BACK-END ############################
$forumdir = $pnsite->getConfig('forumdir');
chdir($forumdir);
require_once('./global.php');
$pnsite is not even defined at this point.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.