PDA

View Full Version : Is it possible to write some PHP inside forum templates?


ArbuZz
07-07-2008, 05:47 PM
I need to add some extra coding in a custom header that I made for the forum. I need to insert some conditional scripting, which I usually accomplish with PHP. Now is it possible to add some PHP in templates? :confused:

veenuisthebest
07-07-2008, 05:53 PM
You cannot use php in the templates. You need to include the php by creating a plugin at the appropriate hook location.

Refer this
http://www.vbulletin.com/docs/html/main/templates_externalfiles

ArbuZz
07-08-2008, 11:03 AM
Ouch...

--------------- Added 1215518983 at 1215518983 ---------------

Not bad. Looks bearable. Thanks for the tip.

ArbuZz
07-10-2008, 12:52 PM
I was able to insert some pure PHP things in the header. However I cannot connect to a database, because as soon as I do vBulletin says:

Fatal error: Call to a member function query_read_slave() on a non-object in .../forum/index.php on line 413

Although I use my one connection resource :( Isn't it possible to make a separate mysql connection to a different database and still make everything work?

Dismounted
07-10-2008, 02:22 PM
As long the MySQL user for vBulletin can access your other database (ie. is on the same server and has SELECT/INSERT/etc. permissions), you can use the "database.table.field" syntax.
$vbulletin->db->query_read("
SELECT *
FROM database2.table1.fieldA AS fieldA
WHERE fieldA = $someid
LIMIT 1
");

ArbuZz
07-11-2008, 06:46 AM
Thank you. And is there a place where all db functions of vBulletin are listed?

For example what's wrong with this code:




...
require_once('./includes/init.php'); // includes class_core.php
require_once('./includes/class_dm.php'); // for class_dm_user.php
require_once('./includes/class_dm_user.php'); // for user functions
require_once('./includes/functions.php'); // vbsetcookie etc.
require_once('./includes/functions_login.php'); // process login/logout
...
global $vbulletin;
$useridq = $vbulletin->db->query_read("SELECT userid FROM "
. TABLE_PREFIX . "user WHERE username='{$username}'");
if (!$useridq) return $useridq;
$userid = $useridq['userid'];



DB query just returns nothing :( originally $vbulletin->db->query_read was $vbulletin->db->query_first_slave. But it doesn't work either. How can one print out the error if it happened upon query?

Dismounted
07-11-2008, 07:01 AM
Just include global.php...In your case, you should use query_first() or query_first_slave(), either will work.

Marco van Herwaarden
07-11-2008, 07:03 AM
With a query_read() you will need to use fetch_array() to actually retrieve rows (usually in a loop). If you need a single row, then you can use query_first() or query_first_slave(), these functions will also read the first (and only) row.

ArbuZz
07-11-2008, 10:24 AM
Thank you very much for your notes. Actually everything was alright with the query call. It was a Class that I've used that caused the trouble with some ambiguous code. I've turned it off.