PDA

View Full Version : Call to a member function query_read() on a non-object


Kyojii
07-09-2012, 03:35 AM
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/showthread.php?p=2346244#post2346244 .


<?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
require_once('./global.php');
Add
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
Below this code
require_once('./global.php');
Add
global $db;

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

also using $vbulletin->db->query_read doesn't seem to solve the problem either.

its because in next line you are using $db->fetch_array

Kyojii
07-09-2012, 06:34 AM
Thanks guys.

--------------- Added 1341819639 at 1341819639 ---------------

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 $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
Thanks guys.

--------------- Added 1341819639 at 1341819639 ---------------



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

you can use this also in place of $db.
$GLOBALS['vbulletin']->db