xoops forums

clownxx

Just popping in
Posted on: 2006/11/1 19:15
clownxx
clownxx (Show more)
Just popping in
Posts: 43
Since: 2006/9/20
#1

use $xoposDB in own php file

Hey, i#d like to add some php functions to my xoops. Esspecially id like to add some dbentries. Now i have created a new php file in /own/myfile.php
What do i have to include etc to use the instance of $xoopsDB?
my phpfile is included in am module an the new functions are there called, but in other modules to.
Please help..
Thanks a lot

best regards clownxx

m0nty

XOOPS is my life!
Posted on: 2006/11/2 0:01
m0nty
m0nty (Show more)
XOOPS is my life!
Posts: 3337
Since: 2003/10/24
#2

Re: use $xoposDB in own php file

include_once '../../mainfile.php';


think that's all..

but you have to declare $xoopsDB before you use it in a query.

global $xoopsDB;

clownxx

Just popping in
Posted on: 2006/11/2 17:45
clownxx
clownxx (Show more)
Just popping in
Posts: 43
Since: 2006/9/20
#3

Re: use $xoposDB in own php file

no sorry it doesnt work...

this is my pageconten:

<?php
global $xoopsDB;

include( '../../mainfile.php' ) ;

function writehistory($uid, $toid, $action, $comment){
//schreibt einen historyeintrag

//$historytable = $db->prefix("history");
//die ($historytable);
$historytable = "xoops_history";
$xoopsDB->query("INSERT INTO $historytable (uid, date, action, comment, toid) VALUES ($uid, NOW(), $action, '$comment', $toid)");
}
?>

I cant even tell the error because the screen when "writehistory" is call is blank.....

mdeshane

Just popping in
Posted on: 2006/11/4 21:18
mdeshane
mdeshane (Show more)
Just popping in
Posts: 3
Since: 2006/10/19
#4

Re: use $xoposDB in own php file

Quote:

clownxx wrote:
no sorry it doesnt work...

this is my pageconten:

<?php
global $xoopsDB;

include( '../../mainfile.php' ) ;

function writehistory($uid, $toid, $action, $comment){
//schreibt einen historyeintrag

//$historytable = $db->prefix("history");
//die ($historytable);
$historytable = "xoops_history";
$xoopsDB->query("INSERT INTO $historytable (uid, date, action, comment, toid) VALUES ($uid, NOW(), $action, '$comment', $toid)");
}
?>


Try:

<?php

include( '../../mainfile.php' ) ;

function writehistory($uid, $toid, $action, $comment)
global $xoopsDB;
{
//schreibt einen historyeintrag

//$historytable = $db->prefix("history");
//die ($historytable);
$historytable = "xoops_history";
$xoopsDB->query("INSERT INTO $historytable (uid, date, action, comment, toid) VALUES ($uid, NOW(), $action, '$comment', $toid)");
}
?>

Sometimes it helps to include the file before you call for a function in it...

teibaz

Not too shy to talk
Posted on: 2006/11/24 22:21
teibaz
teibaz (Show more)
Not too shy to talk
Posts: 103
Since: 2004/6/13
#5

Re: use $xoposDB in own php file

Quote:

mdeshane wrote:

Try:

<?php

include( '../../mainfile.php' ) ;

function writehistory($uid, $toid, $action, $comment)
global $xoopsDB;
{
//schreibt einen historyeintrag

//$historytable = $db->prefix("history");
//die ($historytable);
$historytable = "xoops_history";
$xoopsDB->query("INSERT INTO $historytable (uid, date, action, comment, toid) VALUES ($uid, NOW(), $action, '$comment', $toid)");
}
?>


nope :) you cannot write like this, you'll get parse error :)

global $xoopsDB; must be in function

i mean:

function blaBla( $bla, $bla ) {
global $xoopsDB;
//code
}