vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   db query @ postbit_display_start (https://vborg.vbsupport.ru/showthread.php?t=187145)

PntSingularity 08-03-2008 07:25 PM

db query @ postbit_display_start
 
I'm trying to run db queries at the hook postbit_display_start, but for some reason it doesn't seem to work...

When I try this line:
Code:

$foobar = $db->query_read("SELECT username FROM " . TABLE_PREFIX . "user WHERE userid = 1");
...the code fails and showthread.php returns an empty page.

Ideas?


EDIT:
Nevermind, it seems it works when I use the "showthread_postbit_create" hook instead.

Now I need to figure out why I get "Resource id #x" instead of the data I'm looking for... *sigh*

MoT3rror 08-03-2008 08:42 PM

Change your function to query_first then query_read.

Opserty 08-03-2008 09:35 PM

In the postbit_* hooks you will most likely need to use the $this->registry->db variable or the $vbulletin->db variable as those hooks are executed within a class, if I remember correctly.

PntSingularity 08-05-2008 12:00 AM

Quote:

Originally Posted by Opserty (Post 1590767)
In the postbit_* hooks you will most likely need to use the $this->registry->db variable or the $vbulletin->db variable as those hooks are executed within a class, if I remember correctly.

Thanks. But like I said I switched onto another hook that worked better. ;) Thanks for the info though, might need to use those hooks some other time. :)

Quote:

Originally Posted by MoT3rror (Post 1590747)
Change your function to query_first then query_read.

Umm... why? Unless I'm mistaken query_first reads only the first line whereas query_read reads ALL lines (including the first).


Anyways, I solved the resource id thingy with fetch_array.

MoT3rror 08-05-2008 03:43 AM

Well query_read only does like mysql_query but query_first does mysql_query and fetch_array both and returns the array. Plus you are only pulling out one row with that query.

PntSingularity 08-05-2008 04:07 AM

Quote:

Originally Posted by MoT3rror (Post 1591619)
Well query_read only does like mysql_query but query_first does mysql_query and fetch_array both and returns the array. Plus you are only pulling out one row with that query.

Ah ok, now I understand. Thing is that I wanted all rows, I just hadn't figured out how to do that yet. I'm basically learning php while writing a plugin. :rolleyes:

Marco van Herwaarden 08-05-2008 07:23 AM

To get more then 1 row, you will need to do your query_read() followed by a fetch_array() in a loop.

PntSingularity 08-05-2008 07:41 AM

Quote:

Originally Posted by Marco van Herwaarden (Post 1591688)
To get more then 1 row, you will need to do your query_read() followed by a fetch_array() in a loop.

Thanks, but like I mentioned...
Quote:

Originally Posted by PntSingularity (Post 1591537)
Anyways, I solved the resource id thingy with fetch_array.

;)

sarahk 08-20-2008 01:05 AM

Quote:

Originally Posted by PntSingularity (Post 1591537)
Anyways, I solved the resource id thingy with fetch_array.

I'm stuck on the same thing (so I appreciate the thread). PntSingularity I'm getting none of the post information when I change to the hook you use! How did you access the post data?

turns out the syntax I was after in the original hook was
Code:

$stories = $this->registry->db->query_first

PntSingularity 08-20-2008 04:21 AM

Quote:

Originally Posted by sarahk (Post 1602737)
I'm stuck on the same thing (so I appreciate the thread). PntSingularity I'm getting none of the post information when I change to the hook you use! How did you access the post data?

turns out the syntax I was after in the original hook was
Code:

$stories = $this->registry->db->query_first

I don't think I ever tried a query_first there. However, I've used the variable Opserty mentioned there with query_read.
Code:

$foo = $this->registry->db->query_read('SQL STRING');
while ($bar = $this->registry->db->fetch_array($foo)) {
  /* Do stuff.. */
}
$this->registry->db->free_result($foo);

If you're using showthread_postbit_create you should simply use $db->query (or query_first, query_read or query_write).

If you're not already doing that, you might want to ssh to the server (if you have that possibility) and tail the error log to receive real-time error reporting.
In a command shell (cmd/terminal):
Code:

ssh example.com -l root
Replace example.com with your domain and enter your root password.
Code:

tail -f /var/log/httpd/error_log
Of course, your log may be in a slightly different location. I'm running apache on Fedora 9 myself.


All times are GMT. The time now is 07:01 AM.

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.01170 seconds
  • Memory Usage 1,741KB
  • 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
  • (6)bbcode_code_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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