Log in

View Full Version : How can I make this php code into a plugin?


derekivey
07-29-2005, 07:10 PM
Hi,

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


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:


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:


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:


<!-- 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, 08: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, 08: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, 08:57 PM
You can use the current connection and prefix the tablenames with your database name. E.g.


SELECT * FROM dbname.tablename WHERE fieldname='lala'

derekivey
07-29-2005, 09:07 PM
Ok, but how would it know my database username and password?