我需要在echo $_GET['id'];
中使用oci_parse
,但似乎无法使其正常运行。我试过在',"等但都没有奏效。
代码:
$stid = oci_parse($conn, "
SELECT COLA,
(SELECT COLB FROM T2 WHERE T2.COLB = echo $_GET['id'];)
FROM T1
WHERE T1.COLA = echo $_GET['id'];
");
答案 0 :(得分:0)
方法1
$stid = oci_parse($conn, "SELECT COLA,
(SELECT COLB FROM T2 WHERE T2.COLB = {$_GET['id']})
FROM T1
WHERE T1.COLA = {$_GET['id']}");
方法 - 2
$stid = oci_parse($conn, "SELECT COLA,
(SELECT COLB FROM T2 WHERE T2.COLB = ".$_GET['id'].")
FROM T1
WHERE T1.COLA = ".$_GET['id']."");
答案 1 :(得分:0)
在查询中使用它之前,你必须做一些验证。
if (ctype_digit($_GET['id'])){
$dIdUser = $_GET['id'];
$stid = oci_parse($conn, "
SELECT COLA,
(SELECT COLB FROM T2 WHERE T2.COLB =$dIdUser ;)
FROM T1
WHERE T1.COLA = $dIdUser;
");
}
答案 2 :(得分:-1)
也许你需要在查询后首先执行查询?
<?php
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
// Parse the statement. Note there is no final semi-colon in the SQL statement
$stid = oci_parse($conn, 'SELECT * FROM employees');
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) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>