嗨我有一个错误,上面写着“致命错误:允许的内存大小为134217728字节耗尽(试图分配40个字节)”。
基本上,在php文件中,我提取用户选择使用我在ORACLE数据库中的包中创建的函数进行搜索的信息。在php中我调用函数,传入参数并显示所有结果。
<?php
$db_connection = oci_connect('DBadmin', 'dbadmin', 'PETLOVERSDB');
if (!$db_connection) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$type = $_GET['type'];
echo $type;
$result;
$resultArray;
$finalResult = ' ';
$sqlVariableFindMyPets = 'BEGIN :pet_variable := pet_search_package.pet_search_type(:p_type_data);END;';
$result = oci_new_cursor($db_connection);
$dataToReceive = oci_parse($db_connection, $sqlVariableFindMyPets);
oci_bind_by_name($dataToReceive, ':pet_variable', $result, -1, OCI_B_CURSOR);
oci_bind_by_name($dataToReceive, ':p_type_data', $type);
oci_execute($dataToReceive);
oci_execute($result, OCI_DEFAULT);
oci_fetch_all($result, $resultArray, null, null, OCI_FETCHSTATEMENT_BY_ROW);
oci_close($db_connection);
if($resultArray == null){
echo "<h2>No results found<h2>";
} else {
foreach($resultArray as $iterator){
$finalResult = $finalResult.'<div class="col-lg-4 col-sm-6">
<div class="properties">
<form action="pet-detail.php" method="POST">
<h4>'.$iterator['PET_TYPE_NAME'].' </h4>
<div class="image-holder"><img src="images/logo2.png" class="img-responsive" alt="properties"/></div>
<h5>'.$iterator['PET_RACE_NAME'].' </h5>
<h5>'.$iterator['PET_COLOR'].' </h5>
<h5>'.$iterator['PET_ENERGY_LEVEL'].'</h5>
<h5>'.$iterator['PET_COND_NAME'].'</h5>
<input class="form-control" type="text" style="display: none" readonly name="pet_code" value="'.$iterator['PET_CODE'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_name" value="'.$iterator['PET_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_type" value="'.$iterator['PET_TYPE_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_race" value="'.$iterator['PET_RACE_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_cond" value="'.$iterator['PET_COND_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_energy" value="'.$iterator['PET_ENERGY_LEVEL'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_learn" value="'.$iterator['PET_LEARN_SKILL'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_vet" value="'.$iterator['VET_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_p_name" value="'.$iterator['PERSON_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_location" value="'.$iterator['PETLOCATION'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_notes" value="'.$iterator['PETNOTES'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_space" value="'.$iterator['PET_SPACE'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_treatment" value="'.$iterator['PET_TREATMENT'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_color" value="'.$iterator['PET_COLOR'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_sickness" value="'.$iterator['PET_SICKNESS_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_med" value="'.$iterator['PET_MED_NAME'].'"/>
<input type="submit" class="btn btn-primary" value="View Details" />
</form>
</div>
</div>';
}
echo $finalResult;
}
?>
ORACLE中的函数是
CREATE OR REPLACE PACKAGE BODY pet_search_package AS
FUNCTION pet_search_type(TYPEPET in VARCHAR2)
RETURN SYS_REFCURSOR
IS
pet_search_result SYS_REFCURSOR;
type_id NUMBER;
BEGIN
select TP.pet_type_code into type_id
from dbadmin.petType TP
where TP.pet_type_name = TYPEPET;
OPEN pet_search_result FOR select pet_type_name, pet_race_name, pet_cond_name, pet_energy_level, pet_learn_skill, vet_name, person_name, petlocation, petnotes, petabandondescription, pet_space, pet_treatment, pet_color, pet_sickness_name, pet_med_name
from pet, pettype, petrace, petCondition, petSize,petEnergy, petlearningskill, veterinary, person, petSpace, pettreatments, petcolor, petsickness, petmedicine
WHERE pettype.pet_type_code = type_id;
RETURN pet_search_result;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN null;
END;
END pet_search_package;
我已经尝试将ini_set('memory_limit', '-1');
放在php文件上但它似乎不起作用。我还读到我必须增加变量?哪个变量和哪里?我该怎么做才能解决这个问题?我不知道发生了什么事。请,任何建议将不胜感激!
PS。我在数据库上尝试了这个功能并且运行得很好
答案 0 :(得分:0)
我的猜测是你有一个大表,你的程序在准备输出时失败。
而不是:
foreach($resultArray as $iterator){
$finalResult = $finalResult.'<div class="col-lg-4 col-sm-6">
<div class="properties">
<form action="pet-detail.php" method="POST">
<h4>'.$iterator['PET_TYPE_NAME'].' </h4>
<div class="image-holder"><img src="images/logo2.png" class="img-responsive" alt="properties"/></div>
<h5>'.$iterator['PET_RACE_NAME'].' </h5>
<h5>'.$iterator['PET_COLOR'].' </h5>
<h5>'.$iterator['PET_ENERGY_LEVEL'].'</h5>
<h5>'.$iterator['PET_COND_NAME'].'</h5>
<input class="form-control" type="text" style="display: none" readonly name="pet_code" value="'.$iterator['PET_CODE'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_name" value="'.$iterator['PET_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_type" value="'.$iterator['PET_TYPE_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_race" value="'.$iterator['PET_RACE_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_cond" value="'.$iterator['PET_COND_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_energy" value="'.$iterator['PET_ENERGY_LEVEL'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_learn" value="'.$iterator['PET_LEARN_SKILL'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_vet" value="'.$iterator['VET_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_p_name" value="'.$iterator['PERSON_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_location" value="'.$iterator['PETLOCATION'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_notes" value="'.$iterator['PETNOTES'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_space" value="'.$iterator['PET_SPACE'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_treatment" value="'.$iterator['PET_TREATMENT'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_color" value="'.$iterator['PET_COLOR'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_sickness" value="'.$iterator['PET_SICKNESS_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_med" value="'.$iterator['PET_MED_NAME'].'"/>
<input type="submit" class="btn btn-primary" value="View Details" />
</form>
</div>
</div>';
}
echo $finalResult;
试试这个foreach循环:
foreach($resultArray as $iterator){
echo '<div class="col-lg-4 col-sm-6">
<div class="properties">
<form action="pet-detail.php" method="POST">
<h4>'.$iterator['PET_TYPE_NAME'].' </h4>
<div class="image-holder"><img src="images/logo2.png" class="img-responsive" alt="properties"/></div>
<h5>'.$iterator['PET_RACE_NAME'].' </h5>
<h5>'.$iterator['PET_COLOR'].' </h5>
<h5>'.$iterator['PET_ENERGY_LEVEL'].'</h5>
<h5>'.$iterator['PET_COND_NAME'].'</h5>
<input class="form-control" type="text" style="display: none" readonly name="pet_code" value="'.$iterator['PET_CODE'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_name" value="'.$iterator['PET_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_type" value="'.$iterator['PET_TYPE_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_race" value="'.$iterator['PET_RACE_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_cond" value="'.$iterator['PET_COND_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_energy" value="'.$iterator['PET_ENERGY_LEVEL'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_learn" value="'.$iterator['PET_LEARN_SKILL'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_vet" value="'.$iterator['VET_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_p_name" value="'.$iterator['PERSON_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_location" value="'.$iterator['PETLOCATION'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_notes" value="'.$iterator['PETNOTES'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_space" value="'.$iterator['PET_SPACE'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_treatment" value="'.$iterator['PET_TREATMENT'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_color" value="'.$iterator['PET_COLOR'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_sickness" value="'.$iterator['PET_SICKNESS_NAME'].'"/>
<input class="form-control" type="text" style="display: none" readonly name="pet_med" value="'.$iterator['PET_MED_NAME'].'"/>
<input type="submit" class="btn btn-primary" value="View Details" />
</form>
</div>
</div>';
}
所以只需在迭代它们时显示结果。您的代码将更有效地使用内存。