Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2008, 07:25 PM
PntSingularity's Avatar
PntSingularity PntSingularity is offline
 
Join Date: Feb 2007
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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*
Reply With Quote
  #2  
Old 08-03-2008, 08:42 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Change your function to query_first then query_read.
Reply With Quote
  #3  
Old 08-03-2008, 09:35 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 08-05-2008, 12:00 AM
PntSingularity's Avatar
PntSingularity PntSingularity is offline
 
Join Date: Feb 2007
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Opserty View Post
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 View Post
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.
Reply With Quote
  #5  
Old 08-05-2008, 03:43 AM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 08-05-2008, 04:07 AM
PntSingularity's Avatar
PntSingularity PntSingularity is offline
 
Join Date: Feb 2007
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MoT3rror View Post
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.
Reply With Quote
  #7  
Old 08-05-2008, 07:23 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

To get more then 1 row, you will need to do your query_read() followed by a fetch_array() in a loop.
Reply With Quote
  #8  
Old 08-05-2008, 07:41 AM
PntSingularity's Avatar
PntSingularity PntSingularity is offline
 
Join Date: Feb 2007
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Marco van Herwaarden View Post
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 View Post
Anyways, I solved the resource id thingy with fetch_array.
Reply With Quote
  #9  
Old 08-20-2008, 01:05 AM
sarahk's Avatar
sarahk sarahk is offline
 
Join Date: Jun 2004
Location: Auckland, New Zealand
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by PntSingularity View Post
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
Reply With Quote
  #10  
Old 08-20-2008, 04:21 AM
PntSingularity's Avatar
PntSingularity PntSingularity is offline
 
Join Date: Feb 2007
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sarahk View Post
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04271 seconds
  • Memory Usage 2,264KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (7)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete