vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Call to a member function query_read() on a non-object (https://vborg.vbsupport.ru/showthread.php?t=285343)

Kyojii 07-09-2012 03:35 AM

Call to a member function query_read() on a non-object
 
I seem to run into this problem a lot and it's always a pain to fix. This is being used to make a bbcode with this mod: https://vborg.vbsupport.ru/showthrea...44#post2346244 .

PHP Code:

<?php
require_once('./global.php');
$query $db->query_read("SELECT `userid`, `username` FROM " TABLE_PREFIX "user WHERE UPPER(`username`) = UPPER(".$value.")");
$user $db->fetch_array($query);

$avatar fetch_avatar_url($user['userid']);
$avatar = ($avatar['hascustom']) ? $avatar[0].'&amp;type=thumb' $avatar[0];

$url fetch_seo_url('member', array('userid' => $users['userid'], 'username' => $users['username']), array(), 'userid''username');
$output "<img style='height: 16px;' src='".$avatar."'><a href='".$url."</a>";

return 
$output;
?>


I added the require_once on global to try and fix it but it didn't work. Every time I have this problem I always find this as well: https://vborg.vbsupport.ru/showthread.php?t=235092 but that never fixed it either. Changing the query to vB::$db->query_read(" simply changes the error saying that the class vB isn't defined. also using $vbulletin->db->query_read doesn't seem to solve the problem either.

Badshah93 07-09-2012 03:50 AM

Below this code
Code:

require_once('./global.php');
Add
Code:

global $db;

cellarius 07-09-2012 04:47 AM

I prefer to have $vbulletin global and use $vbulletin->db.

Badshah93 07-09-2012 05:20 AM

Quote:

Below this code
Code:

require_once('./global.php');
Add
Code:

global $db;

Code:

or you change $db-> with $vbulletin->db
and no need of globalizing $vbulletin as global.php is called.

Quote:

also using $vbulletin->db->query_read doesn't seem to solve the problem either.
its because in next line you are using
Code:

$db->fetch_array

Kyojii 07-09-2012 06:34 AM

Thanks guys.

--------------- Added [DATE]1341819639[/DATE] at [TIME]1341819639[/TIME] ---------------

Quote:

Originally Posted by Badshah93 (Post 2346271)
Code:

or you change $db-> with $vbulletin->db
and no need of globalizing $vbulletin as global.php is called.



its because in next line you are using
Code:

$db->fetch_array

Nope, globalizing $db works however even replacing both lines with $vbulletin->db the error occurs.

Pandemikk 07-09-2012 08:24 AM

Are you using this within a hook? If so, you should remove that require because global.php has already been included.

Badshah93 07-09-2012 08:40 AM

Quote:

Originally Posted by Kyojii (Post 2346282)
Thanks guys.

--------------- Added [DATE]1341819639[/DATE] at [TIME]1341819639[/TIME] ---------------



Nope, globalizing $db works however even replacing both lines with $vbulletin->db the error occurs.

you can use this also in place of $db.
Code:

$GLOBALS['vbulletin']->db


All times are GMT. The time now is 06:52 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.01169 seconds
  • Memory Usage 1,738KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (9)bbcode_code_printable
  • (1)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete