I am currently trying to create a mediawiki extension that has a form with a dropdown list and a submit button. In this form I would like to read all my database objects (tables) in the dropdown. if I run it as a single php script it works fine, and it has the following syntax.
<?php
...
$stid = oci_parse($conn,$query);
oci_execute($stid);
?>
//Form
<form method="get" action="generateScript.php">
<select name="getTable">
</form>
<?php
while ($row = oci_fetch_array($stid)) {
echo "<option value=".$row[0].">".$row[0];
}
...
In the case of mediawiki extensions, you have to put it in a functions and to use mediawiki core global variables for the output.
Therefore, I created 3 functions:
1 function - builds connection with the DB server
2 function - executes my SQL query and returns the result in an array:
public function readData () {
global $wgOracleUser;
//@$_SESSION['getTable'] = $getTableValue;
$ora_conn = $this -> getConnect ();
$schema_name = strtoupper($wgOracleUser);
$stid = oci_parse($this -> getConnect()," SELECT table_name
FROM dba_tables
WHERE owner ='" .$schema_name ."'
ORDER BY table_name");
if(!$ora_conn) {
return "No connection";
}
else {
oci_execute($stid);
while ($row = oci_fetch_array($stid)) {
//fetches into an array
$values[] = $row;
return $values;
//echo var_dump($values);
}
//Close Oracle connection
oci_close($ora_conn);
}
}
3 function - shows the mediawiki html-form with the dropdown and submit:
function showForm() {
global $wgScript, $wgOut;
$msgTabList = $this -> readData();
$wgOut->addHTML('
<tr style="margin-top: 2em">
<td align="right">' . $msgSelTable . '</td>
<td> <select name="formTables"> <option value="">'.$msgTabList.'</option>
</select></td>
</tr>
<tr style="margin-top: 2em">
<td align="right"></td>
<td style="padding-top: 1em" align="right">
<input type="submit" name="Generate wiki script" ' .
'value="' . $msgSubmitButton . '" />
</td>
</tr> :);
Inside the 3 function i try to call the 2nd function, whereas my server throws me an error "Array to string conversion"
How can I get my array values displayed in a dropdown list? or is there another way to display it in the form?
I would appreciate any help.