我正在开发一个CRUD Web应用程序。使用php和oracle数据库。我想通过数据库中的数据填充下拉列表。 这是代码。
queries.php
public static function getAllNames(string $mmid){
$dbUser = "...";
$dbPass = "...";
$dbConn = "(DESCRIPTION = (ADDRESS = (PROTOCOL=TCP)(HOST=...)(PORT=...))(CONNECT_DATA=(SID=...)))";
$conn = oci_connect($dbUser, $dbPass, $dbConn);
$sql = oci_parse($conn,"SELECT * FROM mmPERSON where mmid = :mmid");
oci_bind_by_name($sql, ':mmId', $mmId);
oci_execute($sql, OCI_DEFAULT);
oci_fetch_all($sql);
$results = oci_result($sql, 'FNAME');
return $results;
}
roles.php
<?php
$mmid = filter_input(INPUT_GET, "fname");
require_once './pages/header.php';
require_once './functions/queries.php';
$nameArr = Queries::getAllNames($mmid);
?>
<div class="container">
<div class="panel panel-default">
<div class="panel-body">
<div id="addroles" class="hide" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<div id="resultActivityContent"></div>
</div>
<form class="cmxform" id="addroles">
<legend>Add Roles</legend>
<label for="names">Select Name</label>
<select class="form-control" name="names" id="names">
<option selected disabled></option>
<?php
for ($i = 0; $i < count($nameArr); $i++) {
echo '<option value="' . $nameArr[$i][''] . '">' . $nameArr[$i][''] . '</option>';
}
?>
</select>
<br>
<br>
</form>
</div>
</div>
</div>
当我从roles.php中删除该行代码($ nameArr = Queries :: getAllNames($ mmid);)时,前端是可见的,否则页面为空。这行代码有问题。自从过去两天以来我一直试图找出答案。
我是php的新手。请查看代码。任何帮助将不胜感激。