使用php搜索oracle数据库无法正常工作

时间:2013-10-14 05:23:26

标签: php oracle

任何人都可以帮助我......这里有4个字段,一个是oprid,oprname,empid,另一个字段是电子邮件。我想通过oprid,oprname,empid或email进行搜索,但它不起作用,

Operator ID     Operator Name   Person ID   Email ID

警告:oci_execute()要求参数1为资源,在第55行的C:\ xampp \ htdocs \ result \ elishdb \ muti1.php中给出null

警告:oci_fetch_array()期望参数1为资源,在第56行的C:\ xampp \ htdocs \ result \ elishdb \ muti1.php中给出null

   <?php
   {
  include ('connection.php');
  $objParse = null;


  if(isset($_REQUEST['submit'])){

 $optid = '%' . $_POST['OPRID'] . '%';
 $optdec = '%' . $_POST['OPRDEFNDESC']. '%';
 $empid = '%' . $_POST['EMPLID']. '%';
 $empmail = '%' . $_POST['EMAILID']. '%';
  $query ="SELECT * FROM OPERATOR WHERE OPRID LIKE :optid  
 or OPRDEFNDESC LIKE:optdec or EMPLID LIKE :empid
 or EMAILID LIKE :empemail "; 

$objParse = oci_parse ($ora_conn, $query);

 oci_bind_by_name($objParse, ':optid', $optid);
 oci_bind_by_name($objParse, ':optdec', $optdec);
 oci_bind_by_name($objParse, ':empid', $empid);
 oci_bind_by_name($objParse, ':empemail', $empemail);
 }
 ?>

<form action="muti1.php" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="500" border="1" align="center">  
<tr>  
 <th>Operator ID
  <input name="OPRID" type="text" id="OPRID" value="";>  
  <tr>  
 <th>Operator Name
  <input name="OPRDEFNDESC" type="text" id="OPRDEFNDESC" value="";>  
  <tr>  
  <th>Person ID
  <input name="EMPLID" type="text" id="EMPLID" value="";>  
  <tr>  
  <th>Email ID
  <input name="EMAILID" type="text" id="EMAILID" value="";>  
  <input type="submit" value="Search"></th>  
  </tr>  
  </table>  
  </form> 

   <table>
   <tr>
   <td>Operator ID</td>
   <td>Operator Name</td>
   <td>Person ID</td>
   <td>Email ID</td>
   </tr>
   </table>
    <?  

  $success = oci_execute($objParse);
   while($objResult = oci_fetch_array($objParse, OCI_RETURN_NULLS+OCI_ASSOC)) 
   {  
  if ($objParse == null)
  {


 echo "fail";
 }
 else
  {
 ?>  
  <tr>  
 <td><div align="center"><?=$objResult["OPRID"];?></div></td>  
 <td><?=$objResult["OPRDEFNDESC"];?></td>  
 <td><?=$objResult["EMPLID"];?></td>  
 <td><div align="center"><?=$objResult["EMAILID"];?></div></td> 
 <td align="center"><a  href="Optr_Edit.php?OprID=<?=$objResult["OPRID"];?>">Edit</a>  

 </td> 
 </tr>  
  <?  
   }  
    ?>  
 </table>  
  <?  
 oci_free_statement($objParse);
 oci_close($ora_conn); 
   }
   }
  ?>  

2 个答案:

答案 0 :(得分:0)

我感谢您的问题是语法错误。在定义查询变量

时选择后有一个额外的空格

而不是:

$query ="SELECT  * FROM 

尝试:

$query ="SELECT * FROM 

答案 1 :(得分:0)

您必须在SQL查询之外定义$objParse

include ('connection.php');
$objParse = null;
if(isset($_REQUEST['submit'])){
    //........
}

// form here

if ($objParse == null) {
    // echo no result for the given query
} else {
    $success = oci_execute($objParse);
    while($objResult = oci_fetch_array($objParse, OCI_RETURN_NULLS+OCI_ASSOC)) 
    { 
        // print results here
    }
}