calling a stored procedure

redowl 04 May, 2012
I have a form containing 2 drop down boxes and a button

what i would like is that the button calls a stored procedure using the values from the boxes as input parameters. my question is what is the best way to do this?

i can think of two things;
1:load a custom code element and add code to execute on the submit event.
2:edit the form code to set the propper code that will be executed when the button is pressed (non submit button)

ofcourse i tried some things but were unable to get it working so any tips on how to do this are welcome:)

p.s. i dont expect a return value or anything it only has to execute the stored procedure
thanks in advance
GreyHead 05 May, 2012
Hi redowl,

1) will work OK

2) will work if you set up an Ajax link from the button to the procedure file.

Bob
redowl 05 May, 2012
thanks grayhead,

i have this code now:
<?php
$mysql = mysql_connect("localhost", "dbname", "dbpwd");
mysql_select_db("dbname", $mysql);
$jr = $form->data['JAAR'];
$wk = $form->data['WEEK'];
$rs = mysql_query( "CALL MAKEROSTER($wk, $jr)" );
?>


problem one: this code creates a new connection and thus requires a plain text password, instead i would like to use the current connection. is this posible and if so how should i do that?
GreyHead 05 May, 2012
Hi redowl,

In the OnSubmit event you can use a Custom Code action:
<?php
$var1 =& $form->data['var1'];
$var2 =& $form->data['var2'];
$db =& JFactory::getDBO();
$query = "
  CALL MAKEROSTER({$var1}, {$var2});
";
$db->setQuery($query);
$result = $db->query();
?>

Bob
redowl 06 May, 2012
thank you
it worked like a charm😉

p.s. accept in your code u set var1 twice but its just a typo
This topic is locked and no more replies can be posted.