vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How can I make this php code into a plugin? (https://vborg.vbsupport.ru/showthread.php?t=93156)

derekivey 07-29-2005 06:10 PM

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

Marco van Herwaarden 07-29-2005 07:16 PM

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.

derekivey 07-29-2005 07:29 PM

Oh ok. Thanks.

Ok, Any idea of some urls t hat can tell me how to connect to another database in vB?

Dean C 07-29-2005 07:57 PM

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]

derekivey 07-29-2005 08:07 PM

Ok, but how would it know my database username and password?


All times are GMT. The time now is 07:37 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.01830 seconds
  • Memory Usage 1,734KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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