Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 10-11-2009, 08:19 AM
mouth mouth is offline
 
Join Date: Jun 2009
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default undefined method db::query_first_slave() in class_dm_threadpost.php

Hi,

Version = 3.8.4 (PL1)

I am attempting to use the data manager to create a new thread in the forums. A user add an entry to an external calendar and I want to create a new thread in the forums for the external calendar entry.

I have some test code that has vBulletin data manager code only and that works fine. The thread is successfully added to the database ....

PHP Code:
<?
// Statements for vBulletin insert
$forums_path = $_SERVER['DOCUMENT_ROOT'] . '/forums';
define('VB_AREA', 'External');
define('SKIP_SESSIONCREATE', 1);
define('SKIP_USERINFO', 1);
define('CWD', $forums_path);
require_once(CWD . '/global.php');
require_once(CWD . '/includes/class_dm.php');
require_once(CWD . '/includes/class_dm_threadpost.php');
require_once(CWD . '/includes/functions_databuild.php');
// Statements for vBulletin insert
?>

<html>
<head>
<title>Events Calendar</title>
<link rel="stylesheet" type="text/css" href="/style.css">
</head>
<body>

<?
/* --- Insert calendar item into vBulletin forums --- */
// Statements for vBulletin insert - Refer to statements at the top of this page
$userid = 1;
// pick a forum to add the thread to
$forum_id = 82;
$title = "Testing 1-2-3";
$post_text = "Blah Blah Blah Blah";
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$foruminfo = fetch_foruminfo($forum_id);
$threaddm->set_info('forum', $foruminfo);
$threaddm->set('forumid', $foruminfo['forumid']);
$threaddm->set('userid', $userid);
$threaddm->set('title', $title);
$threaddm->set('pagetext', $post_text);
$threaddm->set('allowsmilie', 1);
$threaddm->set('visible', 1);
$threaddm->pre_save();

if (count($threaddm->errors) > 0)
{
    // Errors occurred. Do not proceed with the save.
    // You may want to loop through $dataman->errors and 
    // display the results the user.
    $errorlist = '';
    foreach ($threaddm->errors AS $index => $error)
    {
        $errorlist .= "<li>$error</li>";
    } 
    echo "<ul>" . $errorlist . "</ul>";
}
else
{
    // No errors occurred.
    // Proceed with the save (see the next step).
    $thread_id = $threaddm->save();
    build_forum_counters($forum_id);
    echo "<br />thread id: " . $thread_id . "\n";

}  
/* --- Insert calendar item into vBulletin forums --- */

?>

</body>
</html>
When I insert this code into my calendar php script, the following fatal error is recorded in the php error log, when the script is run ...

PHP Fatal error: Call to undefined method db::query_first_slave() in [forums path]/includes/class_dm_threadpost.php on line 74

I have ensured that the call to vBulletin's global.php is not inside a function. Here is some of the code from my calendar script ...

PHP Code:
<?
error_reporting(E_ALL);
session_start();

require_once($_SERVER['DOCUMENT_ROOT'] . "/include/common.inc");
require_once($_SERVER['DOCUMENT_ROOT'] . "/include/functions.inc");
require_once("include/config.php");

// connect to the database
$conn = mysql_connect($db_host, $db_user, $db_pass, true) or die("Could not connect to database!");
mysql_select_db($db_name, $conn);

// Statements for vBulletin insert
$forums_path = $_SERVER['DOCUMENT_ROOT'] . '/forums';
define('VB_AREA', 'External');
define('SKIP_SESSIONCREATE', 1);
define('SKIP_USERINFO', 1);
define('CWD', $forums_path);
require_once(CWD . '/global.php');
require_once(CWD . '/includes/class_dm.php');
require_once(CWD . '/includes/class_dm_threadpost.php');
require_once(CWD . '/includes/functions_databuild.php');
// Statements for vBulletin insert
?>

<html>
<head>
[ ... ]
</head>
<body>
[ ... calendar html and php ...]

[ ... vBulletin test code as per above ... ]

[ ... calendar html and php ...]

</body>
</html>
Can anyone point me to where I can further analyse and resolve this? Or perhaps even can see my problem? Thanks.
Reply With Quote
  #2  
Old 10-11-2009, 10:04 AM
Shadab's Avatar
Shadab Shadab is offline
 
Join Date: Apr 2007
Location: Bhopal
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Me again.

Not really sure if chdir()'ing to the vBulletin's directory before including global.php will help;
try and see if this works:

PHP Code:
// [...]

$currentDirectory getcwd();
chdir('/home/path/to/your/vb/forum/');

// Statements for vBulletin insert

// [...]

// Statements for vBulletin insert 

chdir($currentDirectory);
unset(
$currentDirectory);

// [...] 
Reply With Quote
  #3  
Old 10-12-2009, 11:14 AM
mouth mouth is offline
 
Join Date: Jun 2009
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Shadab View Post
Me again.

Not really sure if chdir()'ing to the vBulletin's directory before including global.php will help;
try and see if this works:
Thanks, I appreciate the help and input.
Unfortunately though, it did not work

Any other thoughts as to why this could be occurring?

I've been reading and searching through this forum and I saw a somewhat similar issue whereby the outcome was that the person was also creating and using a mysql connection via php's mysql_connect command and that apparently this command can re-use currently open database connections. My mysql_connect command has the new_link parameter set to true to ensure that an new connection is made and an existing one isn't re-used. Is it possible that vBulletin doesn't have the same parameter set and it's trying to re-use the mysql connection I have already opened?
Reply With Quote
  #4  
Old 10-12-2009, 01:39 PM
Shadab's Avatar
Shadab Shadab is offline
 
Join Date: Apr 2007
Location: Bhopal
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by mouth View Post
Any other thoughts as to why this could be occurring?
Could it be that your custom script uses a global $db variable too; overwriting the one that vBulletin references via $vbulletin->db ?

Does simply initializing vBulletin inside your script (require_once '/global.php') throw this Fatal Error ?
(commenting out all DataManager related code)

I'm running out of ideas. :erm: Sorry.
We may need someone who's more experienced in vB to look into this.
Reply With Quote
  #5  
Old 10-12-2009, 02:42 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried taking out the lines connecting to your database and just using vb's method to connect to the database? Since you are calling vb scripts in your page, you are using two different methods to connect to the database and that may be causing problems.
Reply With Quote
Reply

Thread Tools
Display Modes

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 07:08 PM.


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.07167 seconds
  • Memory Usage 2,206KB
  • Queries Executed 11 (?)
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)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)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
  • (5)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_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