1
clownxx
use $xoposDB in own php file
  • 2006/11/1 19:15

  • clownxx

  • Just popping in

  • Posts: 43

  • Since: 2006/9/20


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

2
m0nty
Re: use $xoposDB in own php file
  • 2006/11/2 0:01

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


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


think that's all..

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

global $xoopsDB;

3
clownxx
Re: use $xoposDB in own php file
  • 2006/11/2 17:45

  • clownxx

  • Just popping in

  • Posts: 43

  • Since: 2006/9/20


no sorry it doesnt work...

this is my pageconten:

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.....

4
mdeshane
Re: use $xoposDB in own php file
  • 2006/11/4 21:18

  • mdeshane

  • Just popping in

  • Posts: 3

  • Since: 2006/10/19


Quote:

clownxx wrote:
no sorry it doesnt work...

this is my pageconten:

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:


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...

5
teibaz
Re: use $xoposDB in own php file
  • 2006/11/24 22:21

  • teibaz

  • Not too shy to talk

  • Posts: 103

  • Since: 2004/6/13


Quote:

mdeshane wrote:

Try:


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
}

Login

Who's Online

426 user(s) are online (304 user(s) are browsing Support Forums)


Members: 0


Guests: 426


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits