Different environment between server/localhost is changing the date format - php pdo mysql/oci -
i'm having problems configure server environment, php pdo not formatting date localhost. test it, created 2 connections (using pdo oci , mysql). on localhost, oci , mysql runs normally, on server mysql maintains right format.
important detail: on sqldeveloper, shows info in same format localhost pdo/oci.
my localhost windows 7 , server linux debian x64.
what happening pdo/oci on server?
code:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>documento sem tÃtulo</title> </head> <body> <?php seek { $params->host = "172.0.0.0:1521"; $params->dbname = "geo"; $params->user = "root"; $params->pass = ""; $conn = new pdo("oci:dbname=//$params->host/$params->dbname;charset=utf8", "$params->user", "$params->pass"); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); $stmt = $conn->prepare("select * tb_geooficio tipo = 1 , cadastro_im = 37693500 "); $stmt->execute(); $result = $stmt->fetchall(pdo::fetch_assoc); print_r($result); } catch(exception $e) { echo $e->getmessage(); } ?> <?php seek { $host = "200.0.0.1"; $user = "postmaster"; $pass = "^postm@ster^"; $db = "bd_controleinternet"; $conn = new pdo("mysql:host=$host; dbname=$db", "$user", "$pass"); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); $stmt = $conn->prepare("select * tbl_secretaria sec_id = 7"); $stmt->execute(); $result = $stmt->fetchall(pdo::fetch_assoc); print_r($result); } catch(exception $e) { echo $e->getmessage(); } ?> </body> </html>
result:
in oracle, can utilize next alter default format used date conversion match mysql default:
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
this create oracle dates output mysql dates do.
you can create happen on every connect pdo:
$driver_options = array( pdo::mysql_attr_init_command => 'alter session...' ); seek { $dbh = new pdo($dsn, $user, $pw, $driver_options); } grab (pdoexception $e) { // handle exception }
both oracle , mysql have functions format dates explicitly, can phone call in expressions in query select-list. in oracle function to_char() , in mysql function date_format(), makes harder write rdbms-independent code.
re comment:
it seems nls_date_format can set globally in initorcl.ora
, can set logon trigger, can set @ session level, etc. business relationship different behavior in 2 different environments. here's interesting post it:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::p11_question_id:351017764854
php mysql oracle pdo
No comments:
Post a Comment