查询在php

时间:2015-06-24 21:32:52

标签: php oracle

嗨我有一个oracle bd的查询,它显示路由和停止,当我在开发人员oracle中运行时像魅力一样,但是在我的php文件中复制查询时没有显示任何内容。

我认为问题是语法,但我不知道在哪里,变量$ bus,$ fecha和$ ruta运作良好

这是查询

SELECT * FROM  (
SELECT DISTINCT B.BUSNUMBER,
                OP.Stopid,
                OP.GPSX,
                OP.GPSY,
                L.SHORTNAME,
                OP.TELEGRAMDATE
  FROM Sgco.OPERATIONALINFO OP, sgco.LINES L, sgco.BUSES B
  WHERE  L.PLANVERSIONID =
              (SELECT MAX (p.planversionid)
                 FROM sgco.planversions p
                WHERE     PLANVERSIONID NOT IN ('9001', '9000')
                      AND p.activationdate <=
                             (SELECT TO_CHAR (SYSDATE, 'dd/mm/YYYY')
                                FROM DUAL)
                      AND B.PLANVERSIONID = L.PLANVERSIONID) 
       AND L.LINEID = OP.LINEID
       AND OP.LINEID =
              (SELECT lineid
                 FROM sgco.lines
                WHERE     shortname = UPPER ('$ruta')
                      AND planversionid = L.PLANVERSIONID)      
       AND B.BUSID = OP.BUSNUMBER

UNION ALL

SELECT  DISTINCT B.BUSNUMBER,
               OP.Stopid,
               OP.GPSX,
               OP.GPSY,
               L.SHORTNAME,
               OP.TELEGRAMDATE
  FROM Sgco.OPERATIONALINFO OP, sgco.LINES L, sgco.BUSES B
  WHERE     B.PLANVERSIONID =
              (SELECT MAX (p.planversionid)
                 FROM sgco.planversions p
                WHERE     PLANVERSIONID NOT IN ('9001', '9000')
                      AND p.activationdate <=
                             (SELECT TO_CHAR ('$fecha')
                                FROM DUAL)
                      AND L.PLANVERSIONID = B.PLANVERSIONID)
       AND B.BUSID = OP.BUSNUMBER
       AND OP.BUSNUMBER =
              (SELECT BUSID
                 FROM SGCO.BUSES
                WHERE BUSNUMBER = '$bus' 
                AND planversionid = B.PLANVERSIONID)
       AND L.LINEID = OP.LINEID
) x

WHERE  TELEGRAMDATE = (SELECT MAX(TELEGRAMDATE) FROM OPERATIONALINFO)

php的一部分

<form action="<?php  htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
Ruta:<input type="text" name="ruta"><br>
<input name="bus" type="submit" ><br>
bus:<input type="text" name="bus"><br>
<input name="ruta" type="submit" ><br>
</form> 



<script>


                    <?php

error_reporting(E_ALL); ini_set('display_errors', 1);

    if(isset( $_POST["ruta"])) {

    }
    if(isset( $_POST["bus"])) {

    }


$ruta = $_POST["ruta"];
$bus = $_POST["bus"];
$fecha = date("d/m/Y");
$db ="---line of conection--";
$connect = oci_connect(--user pass--, $db);



$query = "--The query--";

$result = oci_parse($connect, $query);
 oci_execute($result);
  // Now iterate over all placemarks (rows)


$i=0;
while (($row = oci_fetch_array($result, OCI_BOTH)) != false)
 {


echo $datosq [$i][0]=$row[0];//stoid

更新

显示此whit error_reporting(E_ALL); ini_set('display_errors',1);

<b>Warning</b>:  oci_execute() [<a href='function.oci-execute'>function.oci-execute</a>]: ORA-01843: not a valid month in <b>/var/www/html/busestr/pruebabuses.php</b> on line <b>108</b><br />
<br />
<b>Warning</b>:  oci_fetch_array() [<a href='function.oci-fetch-array'>function.oci-fetch-array</a>]: ORA-24374: define not done before fetch or execute and fetch in <b>/var/www/html/busestr/pruebabuses.php</b> on line <b>113</b><br />

1 个答案:

答案 0 :(得分:1)

在比较日期和文本值时,问题是可行的。 p.activationdate是DATE类型,对吗? 表达

p.activationdate <= (SELECT TO_CHAR (SYSDATE, 'dd/mm/YYYY')
                            FROM DUAL)

然后导致CHAR和DATE之间的隐式转换。您不能依赖隐式日期格式。 更好的是直接比较日期

p.activationdate <= SYSDATE

表达

p.activationdate <= (SELECT TO_CHAR ('$fecha')
                            FROM DUAL)

很奇怪。什么是'$ fetcha'的结果?它的类型和价值是什么?没有提供数据格式,to_char使用默认格式。再次 - 你不能依赖它。如果$ fecha = date('d / m / Y'),请使用

p.activationdate <= TO_DATE ('$fecha','dd/mm/yyyy')