Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
Fatal error: Call to a member function query() on a non-object
Old 10-20-2008, 09:58 PM Fatal error: Call to a member function query() on a non-object
Junior Talker

Posts: 4
Trades: 0
Hey guys I'm trying to make this work ... I'm installing Alicebot Scripts to my Invision Power Board Forum. They never rescripted it to work with the newer versions so I've been doing it slowly. But I'm lost for some reason to this ..

Error
Quote:
Fatal error: Call to a member function query() on a non-object in /home/jordanr/public_html/forums/sources/lib/botloader.php on line 95
Full File (THE LINE IN QUESTION HAS BEEN HIGHLIGHTED)

Quote:
<?php
/*
+--------------------------------------------------------------------------
| Alice Bot for IPB v2.0
| =============================================
| by Stephen Mudra
| (c) 2005 MunjMedia, Inc
| http://www.munjmedia.com/
| =============================================
| Using Code from the ALICE Bot Program E
| Which is Copyright 2002, Paul Rydell
+--------------------------------------------------------------------------
*/

if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class botloader {
//-----------------------------------
// User Editable Elements
//-----------------------------------
var $botname = "Constantine"; // The Username of the user you wish to use as your bot
var $botid = 12; // The ID Number of the user you wish to use as your bot
var $forumids = "64"; // The Forum ID numbers of the forums you wish the bot to reply to (Seperate Each New Entry With a ',' without the ')
//-----------------------------------
// End User Editable Elements
// Edit at your own risk
//-----------------------------------
var $respondloaded = 0;
//================================================== =========
// BotLoader
//
// Check if the file exists, sets up basic functions
//================================================== =========
function botloader() {
if(!file_exists( ROOT_PATH.'alicebot/src/respond.php' ) ){
$this->respondloaded = 0;
return 0;
}else{
$this->respondloaded = 1;
return 1;
}
}
//================================================== =========
// Start Alice
//
// Parse the posts and sends to the Alice bot for response
//================================================== =========
function startalice($tid) {
global $ibforums, $DB, $std, $HTTP_POST_VARS;
$exploded = explode(",", $this->forumids);
if( !$this->respondloaded || !in_array($this->forum['id'], $exploded) ) {
return 0;
}else{
$numselects=0;
require_once( ROOT_PATH.'alicebot/src/respond.php' );
}
$botpost = $ibforums->input['Post'];

$botpost = preg_replace("#^(.*)\[/quote\]#ies","",$botpost);
$botresponse = reply($botpost, $ibforums->member['id']);

$postcontent = $botresponse->response;
$postcontent = str_replace("<br />" , "\n" , $postcontent);
$postcontent = str_replace("<br>" , "\n" , $postcontent);
$postcontent = str_replace("<BR>" , "\n" , $postcontent);
$postcontent = preg_replace("#\.[^ ]#", ". \\1", $postcontent);
$finalresponse = "[ quote] ".$ibforums->input['Post']." [ /quote]\r\n".$postcontent;
$this->postreply($tid, $finalresponse);
}
//================================================== =========
// PostReply
//
// Posts the reply to the topic
//================================================== =========
function postreply($tid, $post) {
global $ibforums, $DB, $std;
$DB->query("SELECT * FROM los_topics WHERE tid='".$tid."'");
if(!$DB->get_num_rows()){ return ""; }
$this->topic = $DB->fetch_row();
//----------------------------------------
// Post Details, mmm posty
//----------------------------------------
$this->post = array(
'author_id' => $this->botid,
'use_sig' => 1,
'use_emo' => 1,
'ip_address' => $ibforums->input['IP_ADDRESS'],
'post_date' => time(),
'icon_id' => 0,
'post' => $this->parser->convert( array( 'TEXT' => $post, 'SMILIES' => 0, 'CODE' => 1, 'HTML' => 0 ) ),
'author_name' => $this->botname,
'new_topic' => 1,
'queued' => 0,
'post_htmlstate' => 0,
'topic_id' => $this->topic['tid']
);

//----------------------------------------
// Add topic to DB
//----------------------------------------
$DB->do_insert('posts', $this->post);
$this->post['pid'] = $DB->get_insert_id();

//----------------------------------------
// Update topic with firstpost ID
//----------------------------------------
$DB->simple_construct( array( 'update' => 'topics', 'set' => "topic_firstpost=".$this->post['pid'],'where' => "tid=".$this->topic['tid'] ) );
$DB->simple_exec();

//----------------------------------------
// Add to forum's last post?
//----------------------------------------
$dbs = array( 'last_title' => $this->topic['title'],
'last_id' => $this->topic['tid'],
'last_post' => time(),
'last_poster_name' => $this->botname,
'last_poster_id' => $this->botid );
//-----------------------------------------
// Get the correct number of replies and queued replies
//-----------------------------------------
$DB->simple_construct(array('select' => 'COUNT(*) as posts', 'from' => 'posts', 'where' => "topic_id={$this->topic['tid']} and queued != 1"));
$DB->simple_exec();

$posts = $DB->fetch_row();
$pcount = intval( $posts['posts'] - 1 );

$DB->simple_construct(array('select' => 'COUNT(*) as posts', 'from' => 'posts', 'where' => "topic_id={$this->topic['tid']} and queued=1"));
$DB->simple_exec();

$qposts = $DB->fetch_row();
$qpcount = intval( $qposts['posts'] );

//-----------------------------------------
// UPDATE TOPIC
//-----------------------------------------
$update_array = array(
'posts' => $pcount,
'topic_queuedposts'=> $qpcount,
'last_poster_id' => $this->botid,
'last_poster_name' => $this->botname,
'last_post' => time(),
);

$DB->do_update( 'topics', $update_array, "tid={$this->topic['tid']}" );
$ibforums->cache['stats']['total_replies']++;
$this->forum['posts'] = intval($this->forum['posts']);
$dbs['posts'] = ++$this->forum['posts'];
$DB->do_update( 'forums', $dbs, "id=".intval($this->forum['id']) );

//----------------------------------------
// Update forum cache
//----------------------------------------
$std->update_forum_cache();
$std->update_cache( array( 'name' => 'stats', 'array' => 1, 'deletefirst' => 0, 'donow' => 1 ) );
//----------------------------------------
// Do the Postcount Shizit
//----------------------------------------
$pcount = "";
$mgroup = "";

if ($this->forum['inc_postcount']) {
//------------------------------------
// Increment the users post count
//------------------------------------
$pcount = "posts=posts+1, ";
}

//----------------------------------------
// Are we checking for auto promotion?
//----------------------------------------
if ($ibforums->member['g_promotion'] != '-1&-1') {
list($gid, $gposts) = explode( '&', $ibforums->member['g_promotion'] );

if ( $gid > 0 and $gposts > 0 ) {
if ( $ibforums->member['posts'] + 1 >= $gposts ) {
$mgroup = "mgroup='$gid', ";

if ( USE_MODULES == 1 ) {
$this->modules->register_class(&$this);
$this->modules->on_group_change($ibforums->member['id'], $gid);
}
}
}
}

$ibforums->member['last_post'] = time();
$DB->simple_construct( array( 'update' => 'members',
'set' => $pcount.$mgroup." last_post=".intval($ibforums->member['last_post']),
'where' => 'id='.$ibforums->member['id']
) );

$DB->simple_exec();
}
}
?>
Appreciate any responses thanks!

Last edited by UBASmith; 10-20-2008 at 10:00 PM..
UBASmith is offline
View Public Profile
 
 
Register now for full access!
Old 10-20-2008, 10:34 PM Re: Fatal error: Call to a member function query() on a non-object
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I don't see where $DB is being initiated. PHP is expecting an object and is getting null
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
View Public Profile Visit NullPointer's homepage!
 
Old 10-20-2008, 10:39 PM Re: Fatal error: Call to a member function query() on a non-object
Junior Talker

Posts: 4
Trades: 0
Hey do you have an MSN etc I could talk to you so I can try to resolve this problem?
UBASmith is offline
View Public Profile
 
Old 10-20-2008, 10:42 PM Re: Fatal error: Call to a member function query() on a non-object
Junior Talker

Posts: 4
Trades: 0
Also botloader is ran from this prompt ... in a IPB Forum File

Quote:
//---------------------------------------
// Start AIBot By MunjMedia Inc
//---------------------------------------
require( ROOT_PATH . 'sources/lib/botloader.php' );
$botloader = new botloader;

$botloader->ipsclass =& $this->ipsclass;
$botloader->forum = &$this->forum;
$botloader->parser = &$this->parser;

$botloader->startalice($tid);
This part appears to run fine is the $DB a part of the IPB forums? Possibly, or ???

I can try ??? $db = new database
UBASmith is offline
View Public Profile
 
Old 10-20-2008, 10:49 PM Re: Fatal error: Call to a member function query() on a non-object
Junior Talker

Posts: 4
Trades: 0
This is in the DB_Prefs which might be part of it ...

Quote:
define("LOOPINGERRORMSG", "Oops. I wasn't paying attention. Tell me again what is going on.");
define("LOOPINGLIMIT",150); // -1 for no limit
define("RANDOMCHANCECLEAN",100); // -1 to never check
define("MINUTESTOKEEPDATA",120); // -1 to keep forever
define("MINUTESTOKEEPCHATLOG",-1); // -1 to keep forever
define("DEFAULTPREDICATEVALUE", "Undefined");
define("PROGRAMEVERSION","v0.08");
// This is where all the AIML and startup.xml resides
$rootdir="../../aiml/";
$DB_HOST="localhost";
$DB_UNAME="********";
$DB_PWORD="*******";
$DB_DB="*******";
$errors="";
sql tables have been made in phpMyAdmin for the bot obviously. While the DB_Pref points the bot to this script, the $DB in the other script I beleive is trying to access the current ipb database? I dont know if that answers your question. The original script came as ipf_forums however I edited it to los_forums because my table prefix was "los_" ..

Let me know if you got any ideas!

Last edited by UBASmith; 10-20-2008 at 10:53 PM..
UBASmith is offline
View Public Profile
 
Old 10-23-2008, 02:31 PM Re: Fatal error: Call to a member function query() on a non-object
Experienced Talker

Posts: 41
Name: Jabis Sevon
Location: Tampere, Finland
Trades: 0
There still is no $db instantiated...
The $botloader works, as it's been instantiated
PHP Code:
//---------------------------------------
// Start AIBot By MunjMedia Inc
//---------------------------------------
require( ROOT_PATH 'sources/lib/botloader.php' );
$botloader = new botloader
I don't see the script requiring the database class, nor instantiating it using the same method as quote above anywhere...

Last edited by jabis; 10-23-2008 at 02:33 PM.. Reason: **** quotings wrong again
jabis is offline
View Public Profile Visit jabis's homepage!
 
Closed Thread     « Reply to Fatal error: Call to a member function query() on a non-object
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25200 seconds with 12 queries