title: PHP ORACLE Select ORA-00933 SQL Command Not Properly Ended
body: <p>I keep getting an ORA-00933 error on a query I am using to create a csv file using Ajax. I am returning a csv but it always contains the ORA-00933 error. I will link the PHP code below that is causing the error and then I will link the error. Thank you for the help.</p>
  
  <pre><code>&lt;?php
  $rangeD_Echo = $_POST["rangeD"];
  $year_Echo = $_POST["year"];
  
  $yearTruncation =  substr($year_Echo, 2);
  $yearTruncationMinusOne = $yearTruncation-1;
  $Start = '1-Oct-'.$yearTruncationMinusOne;
  $End = '30-Sep-'.$yearTruncation;
  
  if ($rangeD_Echo == 'Annual')
  {
      $Start = '1-Oct-'.$yearTruncationMinusOne;
      $End = '30-Sep-'.$yearTruncation;
  }
  else if ($rangeD_Echo == 'Q1 FY')
  {
      $Start = '1-Oct-'.$yearTruncationMinusOne;
      $End = '31-Dec-'.$yearTruncationMinusOne;   
  }
  else if ($rangeD_Echo == 'Q2 FY')
  {
      $Start = '1-Jan-'.$yearTruncation;
      $End = '31-Mar-'.$yearTruncation;
  }
  else if ($rangeD_Echo == 'Q3 FY')
  {
      $Start = '1-Apr-'.$yearTruncation;
      $End = '30-Jun-'.$yearTruncation;   
  }
  else if ($rangeD_Echo == 'Q4 FY')
  {
      $Start = '1-Jul-'.$yearTruncation;
      $End = '30-Sep-'.$yearTruncation;
  }
  
  
  $Start = settype($Start, 'string');
  $End = settype($End, 'string');
  /*** CSV File Creation Land ***/
  header('Content-Type: text/csv; charset=utf-8');
  header('Content-Disposition: attachment; filename=d-Report.csv');
  
  $output = fopen('php://output', 'w');
  
  fputcsv($output, array('Week Ending', 'No', 'Project Title', 'Project Contact', 
                         'Org', 'SNo', 'NNo', 'Verified By', 'Date Verified', 
                         'Comments', 'Notes'));
  
  /*** connect to SQL DB ***/
  $dbe = get_db_connection('db');
  $dbe-&gt;connect();
  /*** connect or ORACLE DB ***/
  $db = oci_connect('QUERY','pw','server:1521/view');
  if (!$db){
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  } 
  
  $query = "SELECT * FROM dbo.dbview WHERE (STATUS = 'ACTIVE' OR STATUS = 'CLOSED') AND PNUMBER &lt;&gt;' ' AND AMENDMENT_DATE_CREATED BETWEEN TO_DATE(:startT, dd-mm-yy) AND TO_DATE(:doneT, dd-mm-yy)
                                                                                                                      ORDER BY AMENDMENT_DATE_CREATED DESC";                                                                                                      
  $runQuery = oci_parse($db, $query);
  oci_bind_by_name($runQuery, ":startT", $Start);
  oci_bind_by_name($runQuery, ":doneT", $End);
  oci_execute($runQuery);
  
  while($row = oci_fetch_array($runQuery, OCI_ASSOC+OCI_RETURN_NULLS))
  {
      $WNumber = $row['PNUMBER']."-".$row['DNUMBER'];
  
      $querySQLDB = "SELECT [Verified_By], [Comments], [Notes], [Date_Verified] 
             FROM dbo.Information 
             WHERE dbo.Information.W_Key_ID = '$WNumber' 
             ORDER BY dbo.Information.ID DESC";
      $dbe-&gt;query($querySQLDB);
      $sqlData = $dbe-&gt;fetch();
  
      $dateNoTime = str_replace("12:00:00:000AM"," ",$sqlData['Date_Verified']);
  
      fputcsv($output, array($row['AMENDMENT_DATE_CREATED'], $WNumber, $row['TITLE'], $row['NAME'], 
                             $row['ORG'], $PNumber, $sqlData['Verified_By'], $dateNoTime,
                             $sqlData['Comments'], $sqlData['Notes']));
  
  }
  fclose($output);
  echo $output;
  ?&gt;
  </code></pre>
  
  <p>Error in CSV:</p>
  
  <pre><code>&lt;b&gt;Warning:&lt;/b&gt;&lt;br/&gt;oci_execute() [&lt;a href='function.oci-execute'&gt;function.oci-execute&lt;/a&gt;]: ORA-00933: SQL command not properly ended&lt;br /&gt;
  </code></pre>