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

Reply
 
Thread Tools Display Modes
  #1  
Old 07-29-2005, 07:10 PM
derekivey derekivey is offline
 
Join Date: Apr 2005
Location: Pennsylvania, USA
Posts: 1,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How can I make this php code into a plugin?

Hi,

I was wondering how I can make this code into a plugin:

PHP Code:
mysql_connect("localhost","username","password");
mysql_select_db("traffic_traffic");

$ts_number_of_users "SELECT * FROM users";
$ts_number_of_userss mysql_query($ts_number_of_users);
$ts_number_of_users_reg mysql_num_rows($ts_number_of_userss);

$credits 0;
while(
$sr mysql_fetch_array($ts_number_of_userss)) {
    
$credits $credits+$sr['credits'];
}

$new_user "SELECT username FROM users ORDER BY id DESC LIMIT 1";
$new_userr mysql_query($new_user);
$new_userrr mysql_fetch_row($new_userr); 
I tried creating it in the plugin manager with the hook location being forumhome_start but I get sql errors on my forum:

Quote:
Originally Posted by Error1
Database error in vBulletin 3.5.0 Release Candidate 1:

Invalid SQL:

SELECT
user.username, (user.options & 512) AS invisible, user.usergroupid,
session.userid, session.inforum, session.lastactivity,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
FROM session AS session
LEFT JOIN user AS user ON(user.userid = session.userid)
WHERE session.lastactivity > 1122666824
ORDER BY username ASC;

MySQL Error : Table 'traffic_traffic.session' doesn't exist
Error Number : 1146
Date : Friday, July 29th 2005 @ 04:08:45 PM
Script : http://192.168.1.25/vbtest/index.php
Referrer : http://192.168.1.25/vbtest/index.php?
IP Address : 192.168.1.20
Username : Derek
Classname : vb_database
and also:

Quote:
Originally Posted by Error2
Database error in vBulletin 3.5.0 Release Candidate 1:

Invalid SQL:

UPDATE session
SET lastactivity = 1122667724, location = '/vbtest/index.php', inforum = 0, inthread = 0, incalendar = 0, badlocation = 0, bypass = 0
WHERE sessionhash = '57f30c4294a9a53452c0f3de55df0c00';

MySQL Error : Table 'traffic_traffic.session' doesn't exist
Error Number : 1146
Date : Friday, July 29th 2005 @ 04:08:48 PM
Script : http://192.168.1.25/vbtest/index.php
Referrer : http://192.168.1.25/vbtest/index.php?
IP Address : 192.168.1.20
Username : Derek
Classname : vb_database
The code for the template is:

Code:
<!-- TrafficSurfer Stats --> 
<tbody> 
        <tr> 
                <td class="thead" colspan="2">
			<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_trafficsurfer')"><img id="collapseimg_forumhome_stats" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_stats].gif" alt="" border="0" /></a> 
                        TrafficSurfer Stats: 
                </td> 
        </tr> 
</tbody> 
<tbody id="collapseobj_forumhome_trafficsurfer" style="$vbcollapse[collapseobj_forumhome_todayusers]"> 
        <tr> 
                <td class="alt2"><img src="$stylevar[imgdir_misc]/stats.gif" alt="<phrase 1="$vboptions[bbtitle]">$vbphrase[x_statistics]</phrase>" border="0" /></td> 
                <td class="alt1" width="100%"><div class="smallfont"> 
               Number of users Preregisterred: $ts_number_of_users_reg, Total Credits Given Out: $credits, Newest User: $new_userrr[0]
                </div></td> 
        </tr> 
</tbody> 
<!-- / TrafficSurfer Stats -->
Any ideas?

Thanks,
Derek
Reply With Quote
  #2  
Old 07-29-2005, 08:16 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I suggest you start by looking into vB or other hack sources and learn to approach the database the vB way.

You are now disconnecting the connection made by vB from the database, and replacing it by your own connection, making all vB queries that follow fail.
Reply With Quote
  #3  
Old 07-29-2005, 08:29 PM
derekivey derekivey is offline
 
Join Date: Apr 2005
Location: Pennsylvania, USA
Posts: 1,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh ok. Thanks.

Ok, Any idea of some urls t hat can tell me how to connect to another database in vB?
Reply With Quote
  #4  
Old 07-29-2005, 08:57 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can use the current connection and prefix the tablenames with your database name. E.g.

[sql]
SELECT * FROM dbname.tablename WHERE fieldname='lala'
[/sql]
Reply With Quote
  #5  
Old 07-29-2005, 09:07 PM
derekivey derekivey is offline
 
Join Date: Apr 2005
Location: Pennsylvania, USA
Posts: 1,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, but how would it know my database username and password?
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 02:17 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.03961 seconds
  • Memory Usage 2,213KB
  • 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
  • (1)bbcode_code
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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