简体   繁体   中英

Oracle Express Edition and PHP

I have connected an Oracle express edition database with PHP code, I need to select data from a table between two dates my code is as below. Please help me to retrieve the data.

when selecting the data between two date ranges I got the following error.

Warning: oci_execute(): ORA-00911: invalid character in C:\\wamp\\www\\trades\\dat.php on line 14

Warning: oci_fetch_array(): ORA-24374: define not done before fetch or execute and fetch in C:\\wamp\\www\\trades\\dat.php on line 18

    <html>
    <body>
 <?php

 $dt1 = $_POST["bday1"];
 $dt2 = $_POST["bday2"];

 // Create connection to Oracle
 $conn = oci_connect("cse", "mahesh123", "XE");

 $query = 'select * from daily_trades where trdt= $dt1';
 $stid = oci_parse($conn, $query);
 $r = oci_execute($stid);

 // Fetch each row in an associative array
 print '<table border="1">';
 while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) {
 print '<tr>';
 foreach ($row as $item) {
 print '<td>'.($item !== null ? htmlentities($item, ENT_QUOTES) : 
 '&nbsp').'</td>';
 }
 print '</tr>';
 }
 print '</table>';

 ?>


 </body>
 </html>

You will most likely need to convert the string into a date using TO_DATE() , depending on the format depends on the pattern you give...

$query = "select * from daily_trades 
            where trdt = TO_DATE('$dt1',  'YYYY-MM-DD')";

But also if you want the dates between two dates, you should use BETWEEN .

$query = "select * from daily_trades 
           where trdt between TO_DATE('$dt1',  'YYYY-MM-DD') 
                          and TO_DATE('$dt2',  'YYYY-MM-DD')";

Just make sure you get the dates the right way round (earliest to latest).

由于您必须将日期作为字符串传递,因此请在$dt1加上单'

$query = "select * from daily_trades where trdt= TO_DATE('$dt1',  'YYYY-MM-DD')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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