Losing database connection

Discussion forum for MOD Writers regarding MOD Development.
Locked
acctman
Registered User
Posts: 103
Joined: Thu Feb 09, 2006 5:48 pm

Losing database connection

Post by acctman »

When I include a phpbb script outside side of forum I receive this error
Fatal error: Call to a member function on a non-object in /home/site/public_html/forums/includes/cache.php on line 51
I checked the file and it appears that its not connect to the phpbb3 database.

is there a way to keep connection when include a file?
this is the complete script i'm using and including it outside of my forum on to my site web page.

Code: Select all

<?php
define('IN_PHPBB', true);
$phpEx = substr(strrchr(__FILE__, '.'), 1); 
$phpbb_root_path = '/home/site/public_html/forums/';

include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

require($phpbb_root_path .'includes/functions_user.php'); 
$topic_limit = request_var('topic_limit', 8);

$forums = array_unique(array_keys($auth->acl_getf('f_read', true)));

$forum_id = request_var('f', 0);
$topic_id = request_var('t', 0);
$forum_sql = empty($forum_id) ? '' : (" AND f.forum_id = '$forum_id'");
$topic_sql = empty($topic_id) ? '' : (" AND p.topic_id = t.topic_id AND t.topic_id = '$topic_id'");
$sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
FROM '. FORUMS_TABLE .' f,'.TOPICS_TABLE.' t, '.POSTS_TABLE.' p,'.USERS_TABLE.' u
WHERE t.forum_id = f.forum_id
AND t.topic_status != 1
AND u.user_id = p.poster_id' . $forum_sql . $topic_sql . (empty($topic_sql) ? ' AND p.post_id = t.topic_last_post_id ' : '') . '
ORDER BY ' . (empty($topic_sql) ? 't.topic_last_post_time DESC' : 'p.post_time DESC') . '
LIMIT 0,' . $topic_limit;
$result = $db->sql_query($sql);

.....
?>

User avatar
tumba25
Former Team Member
Posts: 4430
Joined: Wed Jun 06, 2007 6:42 am
Location: Kokkola, Finland.
Name: Jari Kanerva
Contact:

Re: Losing database connection

Post by tumba25 »

You need to include common.php. It connects to the database for you.
Need a mod/extension created/installed, other custom-coded solution or a server admin? https://tumba25.net

acctman
Registered User
Posts: 103
Joined: Thu Feb 09, 2006 5:48 pm

Re: Losing database connection

Post by acctman »

tumba25 wrote:You need to include common.php. It connects to the database for you.
isn't that what include($phpbb_root_path . 'common.' . $phpEx); is for, or am i missing something

User avatar
tumba25
Former Team Member
Posts: 4430
Joined: Wed Jun 06, 2007 6:42 am
Location: Kokkola, Finland.
Name: Jari Kanerva
Contact:

Re: Losing database connection

Post by tumba25 »

Yeah. Are you sure that line was there before? :oops:

Do a echo on your $sql and check that it's okay.
Need a mod/extension created/installed, other custom-coded solution or a server admin? https://tumba25.net

acctman
Registered User
Posts: 103
Joined: Thu Feb 09, 2006 5:48 pm

Re: Losing database connection

Post by acctman »

tumba25 wrote:Yeah. Are you sure that line was there before? :oops:

Do a echo on your $sql and check that it's okay.
looks fine and it loads perfectly if i call the .php file directly from the forum folder i.e. http://www.site.com/forums/post.php WORKS!... but as an include 'forums/post.php'; it receive the cache 51 error.

this is what the echo of $sql looks like from a direct load
SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username FROM phpbb_forums f,phpbb_topics t, phpbb_posts p,phpbb_users u WHERE t.forum_id = f.forum_id AND t.topic_status != 1 AND u.user_id = p.poster_id AND p.post_id = t.topic_last_post_id ORDER BY t.topic_last_post_time DESC LIMIT 0,8 no errors and works fine, its just with the include it throws and error and loses connection. i do have other php code on my main page.

User avatar
tumba25
Former Team Member
Posts: 4430
Joined: Wed Jun 06, 2007 6:42 am
Location: Kokkola, Finland.
Name: Jari Kanerva
Contact:

Re: Losing database connection

Post by tumba25 »

Set $phpbb_root_path as a relative path from where the calling script is for example './forums/'
Need a mod/extension created/installed, other custom-coded solution or a server admin? https://tumba25.net

Locked

Return to “[3.0.x] MOD Writers Discussion”