简体   繁体   English

如何在php中从oracle中获取选定的数据

[英]How to get selected data from oracle in php

I want to get some data from my oracle database into php through a html form where I search by a string which exists into a column.我想通过一个 html 表单从我的 oracle 数据库中获取一些数据到 php 中,在该表单中我通过一个存在于列中的字符串进行搜索。 I have the following php code and the search form retuns nothing:我有以下 php 代码,搜索表单没有返回任何内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[A-Z0-9]+/", $_POST['name'])){
$name=$_POST['name'];
// Connects to the XE service (i.e. database) on the "localhost" machine
$conn = oci_connect('user', 'pwd', 'localhost/XE');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, 'SELECT  deejays.name,available_dates.data,available_dates.venue,available_dates.location FROM deejays,available_dates WHERE deejays.name LIKE '%W&W%' and pk_id=fk_id');
oci_execute($stid);

echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";

}
else{
echo  "<p>Please enter a search query</p>";
}
}
}
?>
<body>
</body>
</html>

The result I want is for ie the following:我想要的结果是: 在此处输入图像描述

You need to modify your query to include bindable parameters.您需要修改查询以包含可绑定参数。 Here is part of example 4 from the documentation for the oci_bind_name function, which you simply need to adapt to suit your application:以下是oci_bind_name函数文档示例 4的一部分,您只需对其进行调整以适合您的应用程序:

$sql = 'SELECT last_name FROM employees WHERE department_id = :didbv ORDER BY last_name';
$stid = oci_parse($conn, $sql);
$didbv = 60;
oci_bind_by_name($stid, ':didbv', $didbv);
oci_execute($stid);
while (($row = oci_fetch_array($stid, OCI_ASSOC)) != false) {
    echo $row['LAST_NAME'] ."<br>\n";
}

The documentation includes a very good description of what binding is, how to do it, and why it's important for application performance and security.该文档很好地描述了绑定是什么、如何进行以及为什么它对应用程序性能和安全性很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM