PDA

View Full Version : undefined method db::query_first_slave() in class_dm_threadpost.php


mouth
10-11-2009, 08:19 AM
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 ....


<?
// 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 ...


<?
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.

Shadab
10-11-2009, 10:04 AM
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:

// [...]

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

// Statements for vBulletin insert

// [...]

// Statements for vBulletin insert

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

// [...]

mouth
10-12-2009, 11:14 AM
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?

Shadab
10-12-2009, 01:39 PM
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.

Lynne
10-12-2009, 02:42 PM
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.