我在配置服务器环境时遇到问题,带有 PDO 的 PHP 没有像 localhost 那样格式化日期。为了测试它,我创建了两个连接(使用 pdo 和 oci 和 mysql)。在 localhost 上,oci 和 mysql 运行正常,但在服务器上只有 mysql 保持正确的格式。
重要细节:在 sqldeveloper 上,它以与 localhost pdo/oci 相同的格式显示数据。
我的本地主机是 WINDOWS 7,我的服务器是 LINUX DEBIAN X64。
服务器上的 pdo/oci 会发生什么?
代码:
<!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
try
{
$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 * from tb_geooficio where tipo = 1 and cadastro_im = 37693500 ");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
<?php
try
{
$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 * from tbl_secretaria where sec_id = 7");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
</body>
</html>
结果: