【问题标题】:How to get selected data from oracle in php如何在php中从oracle中获取选定的数据
【发布时间】:2015-12-27 00:01:41
【问题描述】:

我想通过 html 表单从我的 oracle 数据库中获取一些数据到 php 中,在该表单中我通过列中存在的字符串进行搜索。我有以下 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>

我想要的结果是:

【问题讨论】:

    标签: php oracle-call-interface


    【解决方案1】:

    您需要修改查询以包含可绑定参数。这是documentationoci_bind_name 函数的example 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";
    }
    

    该文档很好地描述了绑定是什么、如何进行以及为什么它对应用程序性能和安全性很重要。

    【讨论】:

      猜你喜欢
      • 2013-07-20
      • 2021-10-20
      • 1970-01-01
      • 2012-04-30
      • 2021-09-23
      • 2019-08-27
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多