Date queries in Oracle with oci8 php drivers

If you get the following error (ORA-01861), you will have to alter your sessions nls date format.

http://ora-01861.ora-code.com/ »

<?php
$conn = oci_connect('username', 'password', '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = db.host.name)(PORT = 1521))) (CONNECT_DATA = (SID = your_sid))) ');

$query = "alter session set nls_date_format = 'SYYYY-MM-DD HH24:MI:SS'";
$stid2 = oci_parse($conn, $query);
oci_execute($stid2, OCI_DEFAULT);

$query = "select * from table_name where  date >= '2000-01-01 00:00:00'";

$stid = oci_parse($conn, $query);

$r = oci_execute($stid, OCI_DEFAULT);

while($row = oci_fetch_assoc($stid))
{
        print_r($row);
}

oci_close($conn);
?>

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.