PDA

View Full Version : Running a query from plugin ? using default function ?


Vaupell
01-04-2010, 09:39 PM
Is it nessesary to assign a function to simply read some data from db..

Want a plugin to read

Tablename
colum1 |colum2|colum3
------------------------------
data1 | data2 | data 3

and so on.. well you know a table..

But using a query as i would when writing a .php file for vbulletin dont work so well
with plugins.. :(

normal :

$linkstat=$db->query_first("SELECT * FROM " . TABLE_PREFIX . "Tablename WHERE Colum1='1'");
$data1 = htmlspecialchars_uni($linkstat['data1']);
$data2 = htmlspecialchars_uni($linkstat['data2']);
$data3 = htmlspecialchars_uni($linkstat['data3']);

$templater = vB_Template::create('some_template');
$templater->register('data1', $data1);
$templater->register('data2', $data2);
$templater->register('data3', $data3);

print_output($templater->render());


Howewer that just gives some
Fatal error: Call to a member function query_first() on a non-object in C:\xampp\xampp\htdocs\emod\includes\class_bootstra p.php(392) : eval()'d code on line 63

Which i just suppect is becourse the query_first should be something else .

but what. tryed looking at other plugins both from vb and from others
just cant figure them out..

help please.

consolegaming
01-04-2010, 09:52 PM
It's the $db causing the issue. I had the same problem. $db doesn't seem to be defined any more.

$vbulletin->db->query_first()

That should work. Though the quickest change to make it work would just be to add $db = $vbulletin->db; at the start of the plugin.

ragtek
01-04-2010, 10:03 PM
You can also use vB::$vbulletin->db->

They wrote in an blogcomment that $vbulletin->db also will not work, after they finish all the refactoring

Vaupell
01-04-2010, 10:11 PM
how about that...

Lol well i can get $vbulletin->db->query_first working

but vB::$vbulletin.... dont..

i belive its missing something as in vB_?????::$vbulletin
ie : vB_Template::create

ragtek
01-04-2010, 10:17 PM
Which hook are you using?

Vaupell
01-04-2010, 10:26 PM
hook to "process_templates_complete"

any experience using ?

While ($row = $vbulletin->db->fetch_array($data))
{

worried about that ->db->

ragtek
01-04-2010, 10:35 PM
It's working fine for me.


$a = vB::$db->query_first(...);

consolegaming
01-04-2010, 10:36 PM
Also concerning your worry about using ->db-> why not do $db = $vbulletin->db; at the start of the plugin? May not be the neatest solution but it would work. And then you can use $db as you used to.